How can I get the list of attributes of an HTML string using Javascript? Here's my code so far.
function traverse_test(){
var root=document.getElementById('arbre0').childNodes;
for(var i=0;i<root.length;i++){
var lis = root[i];
if (lis =='[object HTMLUListElement]') {
for (var member in lis) {
if (typeof lis[member] == "string") {
var assertion = lis[member];
var resultat = assertion.search(/..Bookmarks/);
if (resultat != -1) {
output.innerHTML+= lis[member];
// Here I'd like to have the list of lis[member] attributes
for(var attr in lis[member].attributes) {
output.innerHTML+=lis[member].attributes[attr].name + "=\""+ lis[member].attributes[attr].value + "\"";
}
break;
}
}
}
}
}
}
parseHTMLAndGetAttributes("<img src=\"test.jpg\" />");
? Or do you want to get attributes from the DOM of an already parsed page? The latter is easier. – Jordanfor(var attr in lis[member].attributes) { alert(lis[member].attributes[attr].name + "=\"" + lis[member].attributes[attr].value + "\""); }
in the spot you've indicated in your comment, and you should see the results you want. – Jordan