jQuery
DOM Manipulation
Get/set text, html, attributes, classes, and insert nodes.
By EZ4Code Team
dommanipulation
Code
// Getters and setters
$("#title").text("New Title");
const html = $("#box").html();
$("#img").attr("src", "pic.jpg").attr("alt", "Picture");
$("input").val("default");
// Class manipulation
$("#el").addClass("active").removeClass("hidden");
$("#el").toggleClass("open");
// Inserting content
$("ul").append("<li>End</li>");
$("ul").prepend("<li>Start</li>");
$("<li>new</li>").appendTo("#list");
// Wrapping and removing
$("#box").wrap("<div class='wrap'></div>");
$("#item").remove(); // removes element + listeners
$("#item").empty(); // removes children onlyExplanation
jQuery methods double as getters (no argument) and setters (with argument). append/prepend/appendTo insert DOM nodes at different positions. remove() detaches the element and its data, while empty() clears just the children.
More jQuery Snippets
Selectors
Select elements by id, class, attribute, and pseudo-filters.
Events & Delegation
Bind handlers with on(), support delegation and namespaced removal.
AJAX Requests
Use $.ajax, $.get, $.post, and load with promises.
Effects & Animation
Show, hide, fade, slide, and animate elements.
Traversing the DOM
Navigate relatives and filter the matched set.
Utility Methods
Iterate, merge, and filter with jQuery helpers.