Jquery select this + class

Jquery

Jquery Problem Overview


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?

Jquery Solutions


Solution 1 - Jquery

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");
});

Solution 2 - Jquery

Maybe something like: $(".subclass", this);

Solution 3 - Jquery

Use find()

$(this).find(".subclass").css("visibility","visible");

Solution 4 - Jquery

What you are looking for is this:

$(".subclass", this).css("visibility","visible");

Add the this after the class $(".subclass", this)

Solution 5 - Jquery

if you need a performance trick use below:

$(".yourclass", this);

find() method makes a search everytime in selector.

Solution 6 - Jquery

Well using find is the best option here

just simply use like this

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

and if there are many classes with the same name class its always better to give the class name of parent class like this

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzurfyxView Question on Stackoverflow
Solution 1 - JqueryAdilView Answer on Stackoverflow
Solution 2 - JqueryKamilView Answer on Stackoverflow
Solution 3 - JquerytechfoobarView Answer on Stackoverflow
Solution 4 - JqueryGabriel ComeauView Answer on Stackoverflow
Solution 5 - JqueryMatricoreView Answer on Stackoverflow
Solution 6 - JquerySandeep GantaitView Answer on Stackoverflow