I saw a piece of code like this:
var pl = document.createElement('tr');
...
pl.file = f;
pl.onclick = function(e){
if(e && e.button == 1){
pl.parentNode.removeChild(pl);
}else{
var url;
if(window.createObjectURL){
url = window.createObjectURL(f)
}else if(window.createBlobURL){
url = window.createBlobURL(f)
}else if(window.URL && window.URL.createObjectURL){
url = window.URL.createObjectURL(f)
}else if(window.webkitURL && window.webkitURL.createObjectURL){
url = window.webkitURL.createObjectURL(f)
}
$("player").src = url;
$("player").play();
}
}
It’s for a audio player. And I was thinking if tr element have a file attribute? I was searched the internet but got nothing.
No, the
<tr>element does not have afileattribute. This means you shouldn’t write the following (invalid) HTML:You can do something very close to that in HTML5 using
data-fileas the attribute’s name, then it’s valid.But you don’t have that on your markup (presumably), you’re just taking a JavaScript object that represents that
<tr>, and adding it a property – not an attribute. To manipulate an actual attribute (likedata-file), you’d have to usesetAttributeandgetAttribute.