Skip to content

Instantly share code, notes, and snippets.

@mboynes
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mboynes/9378908 to your computer and use it in GitHub Desktop.
Save mboynes/9378908 to your computer and use it in GitHub Desktop.
Get html attributes from a given html tag
function get_html_attributes(s) {
var reg = /\s+([^\t\n\r\f \/>"'=]+)(?:\s*=\s*(['"])(.*?)\2)?/,attr = {};
while ((result = reg.exec(s)) !== null) {
attr[result[1]] = result[3];
s = s.replace(reg,'');
}
return attr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment