JQuery

Combining $(this) with selector

TAGs: 0 Comment

Posted By: eligeske on in JQuery

Ok, I know that there are many times where you may be using a click function of an element but you need to use specifically that element you clicked siblings or children. Being able to stack the $(this) selector with other ones can be a little difficult or puzzling at times. Check below on a couple different ways of sticking them together.

Notice in the code that a comma “,” is used and not the concatenation plus “+”.

// find out if a selected element's is visible.
$visible = $(this,":visible").length; // returns true of false
// find out if a selected element's immediate sibling div is visible.
$visible = $(this).next('div:visible').length; // returns true of false
// hide the selected previous siblings element, <span>hide me</span><element>this</element>
$('+ span', this).hide();
// hide the selected element's child with the class name .class
$(".class",this).hide(); // returns true or false

0 Responses to "Combining $(this) with selector"

"SHARING IS CARING"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post