tags:

views:

62

answers:

2
+3  Q: 

Get all attributes

Hi,

is there a way to get the list of attributes set to an element?

example:

<div id="myID" title="I am Title" myAttr="I am something else">Hello World!!!</div>

is there a way to get all the above attributes? I tried this already but nothing so far: $('#myID'.attr(); I tried this aswell:

$('#myID'.attr().each(function(a,b){
    alert(a);
});

did not help either... so any suggestions would be appriciated.

thanks.

+2  A: 

Use this plugin: http://plugins.jquery.com/project/getAttributes

Jan Hančič
i dont really like addons/plugins... it would be my last result... i have already seen that, but thanks
Val
Then look at the code of the plugin to see how it's done, eh?
Jan Hančič
+1  A: 

HTML

<div id="myID" title="I am Title"></div>

JS/jquery

var arr = $('#myID')[0].attributes;
for( i= 0; i< arr.length;i++){
    ar +='\n' +arr[i].nodeName;
}
alert(ar);

///returns:///
id
title

I know this a bit messy but just another way ... :)

Val