Posted By

cerxx on 02/13/19


Tagged

js-hacks


Versions (?)

Get allatributes of element in ALERT


 / Published in: JavaScript
 

URL: http://qaru.site/questions/735928/jquery-get-all-html-attributes#2780473

You can use the DOM attributes property on the underlying jQuery element to extract a NamedNodeMap containing all of the element's attributes. This can be quickly parsed into an object which could be passed directly to .attr().

  1. var attrs = {};
  2. var attrMap = $('#setarea')[0].attributes;
  3. $.each(attrMap, function(i,e) { attrs[e.nodeName] = e.nodeValue; });
  4. for(var key in attrs){
  5. alert( "Key: " + key + " value: " + attrs[key] );
  6. }

Report this snippet  

You need to login to post a comment.