JavaScript / jQuery HTML Elements


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:


Set Text Content

Set the inner text of an HTML element:

jQuery

myElement.text("Hello Sweden!");

Try it Yourself »

JavaScript

myElement.textContent = "Hello Sweden!";

Try it Yourself »


Get Text Content

Get the inner text of an HTML element:

jQuery

myText = $("#02").text();

Try it Yourself »

JavaScript

myText = document.getElementById("02").textContent;

Try it Yourself »



Set HTML Content

Set the HTML content of an element:

jQuery

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

Try it Yourself »

JavaScript

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

Try it Yourself »


Get HTML Content

Get the HTML content of an element:

jQuery

content = myElement.html();

Try it Yourself »

JavaScript

content = myElement.innerHTML;

Try it Yourself »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.