.closest() in jQuery

It helps to returns the first ancestor of the selected element.

.closest()

// To add border and text color of “ul” nearby “span”.

<ul>style will affect here
  <li>
    <span>contents</span>
  </li>
</ul>

$(document).ready(function(){
    $(“span”).closest(“ul”).css({“color”:”yellow”,”border”:”2px solid yellow”});
});

… Read more

:contains() Selector in jQuery

It helps to select all elements that contain the specified text.

.contains()

// HTML Content
<div>Vipin</div>
<div>Kiran</div>
<div>Sanoj</div>
<div>Dhanesh</div>

// To finds all divs containing “Kiran” and underlines them.
$( “div:contains(‘Kiran’)” ).css( “text-decoration”, “underline” );

//OUTPUT

Vipin
Kiran
Sanoj
Dhanesh

… Read more

.contents() in jQuery

It helps to get the children of each element in the set of matched elements, including text and comment nodes.

.contents()

// HTML Content
<div>Data01</div>
<div><i>Data02</i></div>
<div>Data03</div>
<div>Data04</div>

// To search for all the text nodes inside the div element(Italic) and wrap them with a b(bold) element.

$(“div”).contents().filter(“i”).wrap(“<b/>”);

// OUTPUT

… Read more

.css() in jQuery

It helps to sets or returns one or more style properties for the selected elements.

.css()

// To add new styles.

$(“p”).css(“background-color”,”yellow”);
$(“p”).css({“background-color”:”yellow”,”font-size”:”100%”});

… Read more

.data() in jQuery

It helps to attaches data to, or gets data from, selected elements.

.data()

// Store data
$(“#button1”).click(function(){
    $(“#DataDIV”).data(“greeting”, “Hello World”);
});

// Redrive data
$(“#button2”).click(function(){
    alert($(“#DataDIV”).data(“greeting”));
});

… Read more

.dblclick() in jQuery

It helps to bind an event handler to the “dblclick” JavaScript event, or trigger that event on an element.

.dblclick()

// When double-clicking on this element displays the alert:

$( “#target” ).dblclick(function() {
    alert( “Handler for .dblclick() called.” );
});

… Read more

.delay() in jQuery

It helps to Add an element to a selected element.

.delay()

// It will fade slowly.
$(“#div1”).delay(“slow”).fadeIn();

// It will fade quickly.
$(“#div2”).delay(“fast”).fadeIn();

// It will pauses for 800 milliseconds.
$(“#div3”).delay(800).fadeIn();

// It will slides up for 400 milliseconds and then pauses for 800 milliseconds before fading in for 500

… Read more

.delegate() in jQuery

It helps to attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

.delegate()

// To add a paragraph(s) dynamically. When click on existing and added paragraph, it will create new paragraph(s).

… Read more

.dequeue() in jQuery

It helps to removes the next function from the queue, and then executes the function.

.dequeue()

// To Remove the next function from the queue, and then execute the function

$(“div”).queue(function(){
    $(“div”).css(“background-color”,”yello”);
    $(“div”).dequeue();
});

… Read more