I want to use hasClass
in the following code, but that doesn\'t work for me, please see my demo in jsfiddle and tell me, what do I do wrong?
It is not the element that exposes the
IdRelation
class, but its child. Try:
if ($("span input").hasClass("IdRelation")) {
alert("ok");
}
Or maybe, depending on your actual markup:
if ($("span > input").hasClass("IdRelation")) {
alert("ok");
}
The selector in the first code snippet will match all elements that are descendants of a
element, whereas the selector in the second snippet will match all
elements that are direct children of a
element. Both will match the
element in your sample markup.