This selector targets all elements present on the page. It's a powerful way to access everything in the HTML structure.
$("*").css("border", "1px solid red");
With the element selector, you can select all elements of a specific type, such as paragraphs (`<p>`).
$("p").addClass("highlight");
The ID selector targets a single element by its unique ID attribute.
$("#myElement").fadeOut();
You can select all elements with a certain class using the class selector.
$(".myClass").hide();
This selector captures all elements that are currently hidden in the document.
$(":hidden").show();
On the other hand, the visible selector grabs all elements that are currently visible on the page.
$(":visible").addClass("highlight");
This selector targets direct child elements within a specified parent element.
$("#parentElement > .childClass").css("background-color", "yellow");
The ancestor-descendant selector selects descendant elements within a specific ancestor element.
$(".ancestorClass p").css("font-weight", "bold");
This selector helps you find elements that contain specific text content.
$("p:contains('Example')").addClass("highlight");
With the first selector, you can target the very first element among a set of matched elements.
$("li:first").addClass("highlight");
Similarly, the last selector focuses on the last element within a set of matched elements.
$("div:last").addClass("highlight");
This selector lets you select elements with even indices within a set.
$("table tr:even").addClass("even-row");
Conversely, the odd selector targets elements with odd indices within a set.
$("ul li:odd").addClass("odd-item");
The input selector captures various types of input elements like textboxes, text areas, selects, and buttons.
$(":input").attr("disabled", true);
This selector is specialized for selecting all button elements.
$(":button").addClass("btn-styling");
This selector is used to find elements that have at least one child element.
$(".has-children:parent").addClass("parent-element");
The animated selector targets elements that are currently undergoing animation.
$(":animated").stop();
Select elements that are the first child of their parent element.
$("li:first-child").addClass("first-child");
This selector allows you to select elements based on their position in relation to their parent.
$("ul li:nth-child(3)").addClass("third-child");
This selector helps to target elements that do not match a specific value.
$("input[type!='checkbox']").addClass("not-checkbox");
With this selector, you can select sibling elements that come after a specified element.
$("#prevElement ~ .siblings").addClass("selected-siblings");
The adjacent selector picks the element immediately preceded by the specified element.
$(".prev + .next").addClass("adjacent-selected");
Attaches a function to run when an error event occurs.
$("img").error(function() {
$(this).hide();
});
Triggers when the browser window changes its size.
$(window).resize(function() {
console.log("Window resized");
});
Used to scroll in a specified element.
$("#scrollableDiv").scroll(function() {
console.log("Scrolled");
});
Loads the whole page and then executes the rest of the code.
$(document).ready(function() {
console.log("Document is ready");
});
Performs an unload event when the user navigates away from the current webpage.
$(window).unload(function() {
console.log("Page is unloading");
});
Loads data from the server and returns it to the selected element.
$("#result").load("data.html", function() {
console.log("Data loaded successfully");
});
Attaches event handlers to selected elements.
$("button").bind("click", function() {
console.log("Button clicked");
});
Triggers a specified event handler on the selected element.
$("button").click(function() {
console.log("Button clicked");
});
$("button").trigger("click");
Used to trigger a specified event for the selected element without executing its default behavior.
$("a").click(function(event) {
event.preventDefault();
console.log("Link clicked");
});
$("a").triggerHandler("click");
Attaches one or more event handlers for the selected elements and child elements.
$("ul").on("click", "li", function() {
console.log("List item clicked");
});
Removes event handlers attached with the on() method.
$("button").on("click", function() {
console.log("Button clicked");
});
$("button").off("click");
Attaches one or more event handlers to the selected element, executed only once.
$("input").one("focus", function() {
console.log("Input field focused");
});
Used to remove any selected event handlers.
$("button").bind("click", function() {
console.log("Button clicked");
});
$("button").unbind("click");
Used to remove focus from the selected element.
$("input").blur(function() {
console.log("Input field lost focus");
});
Used to focus on an element.
$("input").focus(function() {
console.log("Input field focused");
});
Focuses on the selected element.
$("input").focusin(function() {
console.log("Input field focused in");
});
Removes focus from the selected element.
$("input").focusout(function() {
console.log("Input field focused out");
});
Used to detect the change in value of input fields.
$("input").change(function() {
console.log("Input value changed");
});
Triggers the keydown event whenever the user presses a key on the keyboard.
$("input").keydown(function(event) {
console.log("Key pressed: " + event.key);
});
Triggers the keypress event whenever the browser registers a keyboard input.
$("input").keypress(function(event) {
console.log("Key pressed: " + event.key);
})
Used to trigger the keyup event whenever the user releases a key from the keyboard.
$("input").keyup(function(event) {
console.log("Key released: " + event.key);
});
Starts the click event or attaches a function to run when a click event occurs.
$("button").click(function() {
console.log("Button clicked");
});
Specifies functions to start when the mouse pointer moves over the selected element.
$("div").hover(function() {
console.log("Mouse entered");
}, function() {
console.log("Mouse exited");
});
Checks the visibility of selected elements to toggle.
$("button").click(function() {
$("p").toggle();
});
Works when the mouse pointer moves over the selected elements.
$("div").mouseover(function() {
console.log("Mouse over the div");
});
Used to stop the event propagation to parent elements.
$("button").click(function(event) {
event.stopPropagation();
console.log("Button clicked, event propagation stopped");
});
Used to stop the default action of the selected element from occurring.
$("a").click(function(event) {
event.preventDefault();
console.log("Link clicked, default action prevented");
});