javascript - JQuery get a contiguous sequnce of elements -
i'm trying contiguous array of elements using jquery. exmaple html:
<div class="parent"> <div class="childtype2">1</div> <div class="childtype2">2</div> <div class="childtype2">3</div> <div class="childtype1">4</div> <div class="childtype1">5</div> <div class="childtype1">6</div> <div class="childtype1">7</div> <div class="childtype2">8</div> <div class="childtype1">9</div> <div class="childtype1">10</div> <div class="childtype1">11</div> <div class="childtype1">12</div> </div>
i want return div's containing 4,5,6,7 (the first sequnce of divs class="childtype1").
i tried
$("<div>test</div>")($('.parent .childtype2').siblings('.childtype1').addback());
but of course add div text test after last childtype1 (12).
sorry noob question , bad english! i'm not jquery.
edit:
since div's dynamiclly generated, ended adding each "group" special class post-fix of id related group, , used method described in suspectus's answer. not had in mind, works :d. alot of answers guys!
<div class="parent"> <div class="childtype2">1</div> <div class="childtype2">2</div> <div class="childtype2">3</div> <div class="childtype1 inner">4</div> <div class="childtype1 inner">5</div> <div class="childtype1 inner">6</div> <div class="childtype1 inner">7</div> <div class="childtype2">8</div> <div class="childtype1">9</div> <div class="childtype1">10</div> <div class="childtype1">11</div> <div class="childtype1">12</div> </div> $(".inner") // gives elements required
Comments
Post a Comment