...">

JQuery select class inside parent class

I am trying to select a class inside the same parent link class.

This is 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 the "merchantLink" class is clicked, I would like to load jQuery into the "skuFinder" class

What is the best way to select the skuFinder class?

+4
source share
3 answers
 $("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"); }); 
+3
source

Try:

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

Maybe this can help you.

0
source

Source: https://habr.com/ru/post/1300860/


All Articles