0

I have two elements on which multiple classes are applied something like this

<div class="one two"></div>
<div class="one three"></div>

Through jQuery how can I target the other class of the element if targeted by the common class (in this case 'one')?

$('.one').????
CobaltBabyBear
  • 2,188
  • 6
  • 26
  • 47

3 Answers3

2

try this to see all classes added to element

var classes=$('.one').attr('class').split(" ");
$.each(classes, function(index, cls){
    alert(cls);
});
K D
  • 5,889
  • 1
  • 23
  • 35
1

Try $('.one.two');

or

$('.one.three');

Surjith S M
  • 6,642
  • 2
  • 31
  • 50
0

After a bit of searching I found that jQuery has a special simple function for this. I got what I needed with something like this

if($('.one').hasClass('two')) //do something;
if($('.one').hasClass('three')) // do something;
CobaltBabyBear
  • 2,188
  • 6
  • 26
  • 47