What I am trying to achieve is just to get all class names which are used with a certain element.
The problem is that when I use my various methods to get the class names, only the first class is being returned.
Lets say I have a table, where each <td>
tags have the classes classOne classPart1 classThree
and will thus look something like this:
<table id='gridMain'>
<tr>
<td class = 'classOne classPart1 classThree'></td>
<td class = 'classOne classPart2 classThree'></td>
<td class = 'classOne classPart3 classThree'></td>
<td class = 'classOne classPart4 classThree'></td>
<td class = 'classOne classPart5 classThree'></td>
</tr>
</table>
What I've tried is the following:
var classArray = [];
$("#gridMain .classOne").each(function (ix, element)
{
//Example 1
alert($(this).attr('class'));
//Example 2
$($(this).attr('class').split(' ')).each(function()
{
classArray.push(this);
});
//Example 3
alert(this.className);
}
In Example 1 only 'classOne is returned'. In Example 2, I try to split the classes and create an array, with the same result. The Array Length is 1. Only 'classOne is returned'. And in example 3, only classOne is returned...
Anyone know why this is happening?
Thank you in advance!