Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

output all set attributes of an element [duplicate]

I have a jquery object which represents a input button element on the page. How can I with jquery to output via console.log all properties/attributes of this element?

like image 995
amateur Avatar asked Dec 01 '10 01:12

amateur


1 Answers

Assuming the HTML of the page is

<body>
  <img id="smile" class="big" alt="smile" madeupattribute="yep" src="http://mikegrace.s3.amazonaws.com/forums/stack-overflow/smile.png"/>
</body>

you could do

var domElement = $("img")[0] // [0] returns the first DOM element that jQuery found
$(domElement.attributes).each(function(index, attribute) {
  console.log("Attribute:"+attribute.nodeName+" | Value:"+attribute.nodeValue);
});

Example page => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-get-element-attributes-jquery.html

Example page console output

alt text

like image 86
Mike Grace Avatar answered Nov 03 '22 01:11

Mike Grace