Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select this + class

Tags:

jquery

How can I select a class from that object this?

$(".class").click(function(){         $("this .subclass").css("visibility","visible"); }) 

I want to select a $(this+".subclass"). How can I do this with Jquery?

like image 425
zurfyx Avatar asked Jul 19 '13 12:07

zurfyx


People also ask

How do I select a class in jQuery?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.


1 Answers

Use $(this).find(), or pass this in context, using jQuery context with selector.

Using $(this).find()

$(".class").click(function(){      $(this).find(".subclass").css("visibility","visible"); }); 

Using this in context, $( selector, context ), it will internally call find function, so better to use find on first place.

$(".class").click(function(){      $(".subclass", this).css("visibility","visible"); }); 
like image 70
Adil Avatar answered Oct 07 '22 12:10

Adil