views:

50

answers:

2

I have a HTML DIV element:

<div class="obj" height="this is attr 1" rel="this is att2" width="this is att3"></div>

I've a new Variable: attArray:

var attArray = new Array();

I want to get step by step each att in div.obj into attArray. How do I do it?

attArray[0] = "this is attr1"
attArray[1] = "this is attr2"
attArray[2] = "this is attr3"
+2  A: 

Simple:

$('.obj').each(function() {
   var attArray = [];
   for(var k = 0; k < this.attributes.length; k++) {
       var attr = this.attributes[k];
       if(attr.name != 'class')
          attArray.push(attr.value);
   }
   //do something with attArray here...
});

Working example

Jacob Relkin
Why do you assume they have that format? And even so they're 1-indexed, not 0-index as you implemented.
Alin Purcaru
@Alin, You didn't see my updated answer. :P
Jacob Relkin
I see now, but I still think (or like to think) he wants any element attribute (class, id, title, etc.). Otherwise it's plain boring.
Alin Purcaru
yea.. I forgot somethink.. if in EX: instead 'att1' = 'a' ; 'att2' = e; ' att3 ' = c. How do you resolve this ? TO @Alin : you're right!. :)
Rueta
@Rueta, Try my answer now.
Jacob Relkin
this work! Thankyou, Jacob :).
Rueta
+2  A: 

Each element already has an attributes-collection, you can access it like an array.

Dr.Molle
sorry, my Question at first is'nt clear. Now i update it :)
Rueta