javascript: Checking if tags are next to each other

Posted by user3731759 on Stack Overflow See other posts from Stack Overflow or by user3731759
Published on 2014-06-11T21:01:32Z Indexed on 2014/06/11 21:25 UTC
Read the original article Hit count: 206

Filed under:
|
|
|
|

So here is the problem: I want to check if element <x-statement> is right next to <p> and there is no text in between them. So this will return true:

<div>
     <x-statement>[discover.prev]</x-statement>
     <p>Go forward<p>
</div>

But this won't:

<div>
     <x-statement>[discover.prev]</x-statement>
     im in the way herr der
     <p>Go forward<p>
</div>

This what I've tried to do:

if($(this).next().is('p')){
    alert("p is next to you");
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery