tags:

views:

115

answers:

3

Hi,

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"?

+2  A: 
$("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");
});
rahul
thanks for the nice and thorough answer :D
sf
You are always welcome @sf.
rahul
A: 

Try:

$('a.merchantLink').click(function(){
   var el = $(this).parent().siblings('.skuFinder');
});
Darmen
A: 
$(".merchantLink").click( function(){
    $(".skuFinder").load();
});

May be this can help you.

M.M.H.Masud