Skip to main content

Command Palette

Search for a command to run...

Update DOM element

Published
•1 min read•View as Markdown

In jQuery, you can update the DOM using the text() and html() functions. The equivalents in JavaScript are textContent, and innerHTML attributes.

Refer to the following code snippet to learn how to update an element through jQuery and vanilla JavaScript:

For changing the text inside an element:

// Update an element text using jQuery
$(".login-button").text("Log In");
// Update an element text using vanilla JavaScript
document.querySelector(".login-button").textContent = "Log In";

For changing the HTML inside an element, just adding new elements inside the parent:

// Update an element HTML using jQuery
$(".login-message").html("<div>Login successfull!</div>");
// Update an element HTML using vanilla JavaScript
document.querySelector(".login-message").innerHTML = "<div>Login successfull!</div>";

More from this blog

I

Is A Web Learning

54 posts