jquery - Check if elements has\belongs to the same parent -
i have question. example have html:
<div id="imagediv> <a id="testa"> <img alt="" src "" id="img1"> <img alt="" src "" id="img2"> <img alt="" src "" id="img3"> <img alt="" src "" id="img4"> <img alt="" src "" id="img5"> </a> <img alt="" src "" id="img6"> </div>
how can check, lowest level and, if possible ,with simple jquery selector or extension, images id`s 1 5 has same parent, not image 6th id.
in words: how check if images id`s 1 5 siblings()?
thanks lot
see http://jsfiddle.net/t324lwoy/1/
function aresiblings(e1, e2){ return $(e1).parent().children().is($(e2)); }; console.log(aresiblings("#img1", "#img3")); console.log(aresiblings("#img2", "#img5")); console.log(aresiblings("#img1", "#img6"));
update:
or
function aresiblings(e1, e2){ return $(e1).siblings().is($(e2)); };
Comments
Post a Comment