var cName = $(".cm_lhs").children("div").first().attr('class');
if (cName == "tile_nav") {
alert(cName);
}
How to check element class name contains at least the class name "tile_nav" if there is multiple class names?
var cName = $(".cm_lhs").children("div").first().attr('class');
if (cName == "tile_nav") {
alert(cName);
}
How to check element class name contains at least the class name "tile_nav" if there is multiple class names?
You can use is()
var firstC = $(".cm_lhs").children("div").first();
if (firstC.is(".tile_nav")) {
alert("Present");
}
or hasClass()
var firstC = $(".cm_lhs").children("div").first();
if (firstC.hasClass("tile_nav")) {
alert("Present");
}
or do it manually
var cName = $(".cm_lhs").children("div").first().attr('class');
if (cName.split(' ').indexOf('tile_nav') > -1) {
alert("Present");
}
Use hasClass()
if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
alert("Yes");
}
You can use hasClass
method as follow:
if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
alert("Class present");
}
You can use
hasClass()
if($(".cm_lhs").children("div").first().hasClass('tile_nav')){
alert(cName);
}
You can use hasClass()
of jquery
For e.g.
if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
alert(cName);
}
This works