开发者

How can I check the type of the next element?

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')){}


A chain of .next() and .is() methods would do it in a readable way:

if($('#id').next().is('p')) {
    // it's a paragraph
}


use standard nodeName property

if ($("#id").next().get(0).nodeName == 'P')

get(0) construct returns the underlying DOM element of the JQuery object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜