JavaScript / jQuery HTML Element

jQuery vs JavaScript

jQuery was created by John Resig in 2006. It aims to handle browser incompatibilities and simplify HTML DOM operations, event handling, animations, and Ajax.

For more than a decade, jQuery has been the most popular JavaScript library in the world.

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

Set text content

Set the internal text of the HTML element:

jQuery

myElement.text("Hello China!");

Try It Yourself

JavaScript

myElement.textContent = "Hello China!";

Try It Yourself

Get text content

Get the internal text of the HTML element:

jQuery

var myText = myElement.text();

Try It Yourself

JavaScript

var myText = myElement.textContent || myElement.innerText;

Try It Yourself

Set HTML content

Set the HTML content of the element:

jQuery

var myElement.html("<p>Hello World</p>");

Try It Yourself

JavaScript

var myElement.innerHTML = "<p>Hello World</p>";

Try It Yourself

Get HTML content

Get the HTML content of the element:

jQuery

var content = myElement.html();

Try It Yourself

JavaScript

var content = myElement.innerHTML;

Try It Yourself