jquery nextUntil has element

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-05-14T07:09:07Z Indexed on 2010/05/14 7:14 UTC
Read the original article Hit count: 272

jquery nextUntil has element

I have a bunch of elements like this:

<div></div>
<span></span>
<table></table>
<div></div>
<span></span>
<div></div>

I need to check whether or not there's a table element in between the divs, and if so do something.

$('div').each(function () {
  if ($(this).nextUntil('div').include('table')) {
    $(this).addClass('got-a-table');
  }
}

Something like this? I know that there's no include method, is there something that can get me what I need?

Thanks.

Result should be like this:

<div class='got-a-table'></div>
<span></span>
<table></table>
<div></div>
<span></span>
<div></div>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors