javascript - output all set attributes of an element -
this question has answer here:
- get attributes of element using jquery 4 answers
i have jquery object represents input button element on page. how can jquery output via console.log properties/attributes of element?
assuming html of 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 do
var domelement = $("img")[0] // [0] returns first dom element 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
Comments
Post a Comment