JS TutorialLesson #287

jQuery HTML Elements

[jQuery](/jquery/default.asp) was created in 2006 by John Resig. It was designed to handle Browser Incompatibilities and to simplify HTML DOM Manipulation, Event Handling, Anima...

jQuery vs JavaScript

jQuery was created in 2006 by John Resig. It was designed to handle Browser Incompatibilities and to simplify HTML DOM Manipulation, Event Handling, Animations, and Ajax.

For more than 10 years, jQuery has been the most popular JavaScript library in the world.

However, after JavaScript Version 5 (2009), most of the jQuery utilities can be solved with a few lines of standard JavaScript:


Share

Set Text Content

Set the inner text of an HTML element:

jQuery

Example Code

javascript
Try it Yourself
myElement.text("Hello Sweden!");

JavaScript

Example Code

javascript
Try it Yourself
myElement.textContent = "Hello Sweden!";

Get Text Content

Get the inner text of an HTML element:

jQuery

Example Code

javascript
Try it Yourself
myText = $("#02").text();

JavaScript

Example Code

javascript
Try it Yourself
myText = document.getElementById("02").textContent;

Set HTML Content

Set the HTML content of an element:

jQuery

Example Code

javascript
Try it Yourself
myElement.html("

Hello World

");

JavaScript

Example Code

javascript
Try it Yourself
myElement.innerHTML = "

Hello World

";

Get HTML Content

Get the HTML content of an element:

jQuery

Example Code

javascript
Try it Yourself
content = myElement.html();

JavaScript

Example Code

javascript
Try it Yourself
content = myElement.innerHTML;

Interactive Code Examples

jQuery

javascript
Try it Yourself
JavaScript syntax and algorithm demonstration.
myElement.text("Hello Sweden!");

JavaScript

javascript
Try it Yourself
JavaScript syntax and algorithm demonstration.
myElement.textContent = "Hello Sweden!";

jQuery

javascript
Try it Yourself
JavaScript syntax and algorithm demonstration.
myText = $("#02").text();

JavaScript

javascript
Try it Yourself
Interactive runnable JavaScript example from EA Academy.
Live Output Preview:

jQuery

javascript
Try it Yourself
JavaScript syntax and algorithm demonstration.
myElement.html("<p>Hello World</p>");

JavaScript

javascript
Try it Yourself
JavaScript syntax and algorithm demonstration.
myElement.innerHTML = "<p>Hello World</p>";