For example I have following jQuery code:
var div1 = $("divs").next();
How do I find out that the div1 object really contains 开发者_如何学Goan existing node? For example, $("divs1")
just had no next siblings.
You can check for the length of the result.
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
}
You are aware that divs is not a valid tag name, right ? (hope it is just an example..)
var div1 = $("divs").next();
if (div1.length != 0) {
// valid one
}
精彩评论