如何检查下一个元素的类型? [英] How can I check the type of the next element?
本文介绍了如何检查下一个元素的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查id ="id"之后的元素是段落?
How can i check that element after id="id" is paragraph?
<div>
<p id="id">one</p>
<p>two</p>
</div>
我想要这样的东西,但是可以.
I want something like this, but working.
if ($("#id").next() == $('p')){}
推荐答案
由 .next()
和 .is()
方法将以一种可读的方式做到这一点:
A chain of .next()
and .is()
methods would do it in a readable way:
if($('#id').next().is('p')) {
// it's a paragraph
}
这篇关于如何检查下一个元素的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文