sf.
sf.

Reputation: 25470

Jquery select class inside parent class

I'm trying to select a class inside the same parent class of a link.

This is the html:

<div id="productList">
    <ul>
        <li class="productListItem">                
            Product 1 <span class="smallText">stuff</span>
            <div class="skuFinder"></div>
            <ul class="merchantsInProductList">
                <li><a class="merchantLink" href="/Pricing/SkuFinder/1/1">Merchant 1 $5.99</a></li>                    
            </ul>
        </li>            
    </ul>                
</div>

When class "merchantLink" is clicked, I'd like to perform a jQuery load into the class "skuFinder"

What is the best way to select the class "skuFinder"?

Upvotes: 4

Views: 4320

Answers (3)

M.M.H.Masud
M.M.H.Masud

Reputation: 329

$(".merchantLink").click( function(){
    $(".skuFinder").load();
});

May be this can help you.

Upvotes: 0

Darmen Amanbay
Darmen Amanbay

Reputation: 4871

Try:

$('a.merchantLink').click(function(){
   var el = $(this).parent().siblings('.skuFinder');
});

Upvotes: 0

rahul
rahul

Reputation: 187020

$("a.merchantLink").click(function(){
   // (if div is the previous element to ul)
   $(this).closest("ul.merchantsInProductList").prev("div.skuFinder");

   // (if div is the not previous element to ul and is anywhere inside li with 
   //class productListItem)
   $(this).closest("li.productListItem").find("div.skuFinder");
});

Upvotes: 3

Related Questions