0
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?

PRANAV
  • 1,009
  • 5
  • 16
  • 36
  • possible duplicate of [jQuery .hasClass() vs .is()](http://stackoverflow.com/questions/4901553/jquery-hasclass-vs-is) – mplungjan Jul 03 '15 at 05:22

5 Answers5

1

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");
}
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
1

Use hasClass()

if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
     alert("Yes");
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

You can use hasClass method as follow:

if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
    alert("Class present");
}
Nikhil Batra
  • 3,118
  • 14
  • 19
-1

You can use hasClass()

 if($(".cm_lhs").children("div").first().hasClass('tile_nav')){
    alert(cName);
    }
Nithin Krishnan P
  • 748
  • 1
  • 6
  • 14
-1

You can use hasClass() of jquery

For e.g.

if ($(".cm_lhs").children("div").first().hasClass("tile_nav")) {
alert(cName);
}

This works

Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46