Reputation: 47945
This code check if the class before .trackOn
is called "sideOn" :
if($('.trackOn').prev().attr('class')=="sideOn") alert("before=sideOn");
Now, I'd like to check if after .trackOn
(using .next()
) there isnt any div. How can I do it?
Upvotes: 0
Views: 685
Reputation: 1108742
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.
Unrelated to the question, using jQuery.hasClass()
is better than checking the sole attribute value because it can contain more than one class.
Upvotes: 1