Skip to main content

jQuery HTML DOM

jQuery is a JavaScript library that can be used to manipulate HTML and CSS on a webpage.

Here are some examples of how to manipulate the HTML Document Object Model (DOM) using jQuery:

Selecting elements

$("selector");

Replace "selector" with the CSS selector for the element(s) you want to target.

Changing the text content of an element

$("selector").text("new text content");

This will change the text content of the element(s) to the specified value.

Changing the HTML content of an element

$("selector").html("new <b>HTML</b> content");

This will change the HTML content of the element(s) to the specified value.

Adding an element

$("selector").append("<p>New element</p>");

This will add a new element as a child of the selected element(s).

Removing an element

$("selector").remove();

This will remove the selected element(s) from the DOM

note

Remember to include the jQuery library in your HTML file before using these jQuery code snippets.