jquery - remove duplicate consecutive element -
<div>something need</div> <span>x</span> <div>something need</div> <span>x</span> <div>something need</div> <span>x</span><span>x</span><span>x</span> <div>something need</div> on row have 3 span elements, how remove one? want have 1 between each element.
edit: made html correct people focus on actual issue.
$('span').each(function() { while($(this).prop('tagname') == $(this).next().prop('tagname')) $(this).next().remove(); }); as can see, consecutive spans have been removed, , there 1 x in-between divs instead of three: http://jsfiddle.net/samliew/kfmru/
it practice wrap above elements in container, , perform removal in container. i.e.:
$('#mydiv span').each(function() {
Comments
Post a Comment