jquery - How can I check if two elements/div belong to the same parent? -


hi working on piece of code shopping cart

$('.addtocart').click(function() {      //get button id           var cartid = $(this).attr("id");       //get check box id        var checkboxid = $('input.cartlevelchecked:checked').attr("id");      //get parent id     var levellistid = $(this).closest('li').attr("id");      if(('#'+cartid && '#'+checkboxid).parent('#'+levellistid)){         $(".selectplan").show();     }      //alert(/*cartid + checkboxid +*/ levellistid); }); 

basically i'm checking see if check-box user checked , button clicked on belongs same parent show div

any appreciated. thanks

you need compare levellistid, correctly queried, id of checkbox's closest li parent, should query same way:

if (levellistid === $('#' + checkboxid).closest('li').attr('id')) {     ... } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -