I am using code that requires me to write the following:
document.getElementById("id").innerHTML //+ whatever else
This code is getting used probably 20-30 times in my javascript with only the ID attribute changing. Is there a way I could write a very small function that replace this entire line of text with a more simplified version? Something like:
El("id")
I have written probably 2-3 different functions to attempt to simply this, but none of them have worked.
var dom = {
elem = function (id){
return document.getElementById(id).innerHTML;
}
}
dom.elem(testid) //this has not worked
Try this:
function El(id) {
return document.getElementById(id).innerHTML;
}
Then you can use:
El("elementId"); //will return document.getElementById("elementId").innerHTML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With