例如,我有以下 jQuery 代码:
var div1 = $("divs").next();
如何找出 div1 对象确实包含现有节点?例如,$("divs1")
没有下一个 sibling 。
最佳答案
您可以检查结果的长度。
var div1 = $("divs").next();
if ( div1.length )
{
//it exists..
}
else
{
// no next found..
// keep in mind that it might fail due to two reasons
// a) no next element found
// b) no divs element found
}
您知道 divs 不是有效的标签名称,对吧? (希望这只是一个例子..)
关于jquery - 发现 jQuery 对象确实包含一个现有节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4903749/