So basically I’m trying to select the class “on” only, but based on the class length of 2.
<div class="film cars-0317219 on"></div>
<div class="film wall-e-0910970 on"></div>
<div class="film off up-0945232"></div>
<div class="film on finding-nemo-0266543"></div>
<div class="film off cars-0317219"></div>
Something like:
$('div.film').live('click', function(){
var classes=$(this).attr("class").split(" ");
var status=classes[classes.length=2];
alert(status);
});
Should alert “on”
Any idea how to get the alert based on the string length? (Likewise, if I put 3 instead of 2 in the code, it should alert “off”)
You should do:
arrays in javascript are zero based and so the second element has an index of 1 (and the third element has an index of 2)
EDIT – now i understand the OP means the length of the word on (2 letters):