a neat function that allows this:
document.getElementsByTagName('i').innerHTML="pie";
and it will change the innerHTML of all tags AUTOMATICALLY!!!!
incredible!
a neat function that allows this:
document.getElementsByTagName('i').innerHTML="pie";
and it will change the innerHTML of all tags AUTOMATICALLY!!!!
incredible!
function(z){ | |
Object.defineProperty( | |
NodeList.prototype,z,{ | |
set:function(a,b){ //make a setter function for when property is set on a Nodelist | |
for(b in this) //for every element in the nodelist... | |
if(b=this[b])b[z]=a //set property on element | |
} | |
} | |
) | |
} |
function(z){Object.defineProperty(NodeList.prototype,z,{set:function(a,b){for(b in this)if(b=this[b])b[z]=a}})} |
{ | |
"name": "NodeListProp", | |
"description": "set element properties on nodelists", | |
"keywords": [ | |
"dom", | |
"nodelist", | |
"properties" | |
] | |
} |
<!DOCTYPE html> | |
<title>Foo</title> | |
<i>cake</i> | |
<i>cake</i> | |
<i>cake</i> | |
<i>cake</i> | |
<i>cake</i> | |
<script> | |
( | |
function(z){Object.defineProperty(NodeList.prototype,z,{set:function(a,b){for(b in this)if(b=this[b])b[z]=a}})} | |
)("innerHTML"); | |
document.getElementsByTagName('i').innerHTML="pie"; | |
document.getElementsByTagName('i')[1].style.color="red"; | |
</script> |
Good idea! Thanks!