How do I test if the next element is certain type – e.g. I want to test if the next element following an image, is also an image. If so, then I want to add a class to that element
e.g. if this was the case then it would trigger true and add a class to the first image…
<p></p>
<img />
<img />
<p></p>
However, in this case then it would trigger false, and nothing would happen…
<p></p>
<img />
<p></p>
You can use the
.is()method of jQuery to do that:So to add a class like you describe: