如何检查是否有next()元素 [英] how to check if there is the next() element

查看:73
本文介绍了如何检查是否有next()元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码检查 .trackOn 之前的类是否被称为sideOn:

This code check if the class before .trackOn is called "sideOn" :

if($('.trackOn').prev().attr('class')=="sideOn") alert("before=sideOn");

现在,我想检查一下 .trackOn (使用 .next())没有任何div。我该怎么办?

Now, I'd like to check if after .trackOn (using .next()) there isnt any div. How can I do it?

推荐答案

你可以用 Node.nodeName 获取元素的节点名称。

You can use Node.nodeName to get the element's node name.

if ($('.trackOn').next().get(0).nodeName != 'DIV') alert('Not before a div');

请注意,这始终是大写的。

Please note that this is always uppercased.

使用 jQuery与此问题无关.hasClass() 比检查唯一属性值更好,因为它可以包含多个类。

Unrelated to the question, using jQuery.hasClass() is better than checking the sole attribute value because it can contain more than one class.

这篇关于如何检查是否有next()元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆