I have a function that does several document.getElementById so I want to write a function for it, and I need to access different properties of the element based on the situation, so I created a function but is not working and would like to know if someone can help with it
I tried this:
function getTheValue(id, the_property) {
return document.getElementById(id).the_property;
}
And this:
function getTheValue(id, the_property) {
//alert(id + the_property);
if (the_property === 'value') {
document.write(document.getElementById(id).value);
} else if (the_property === 'innerHTML') {
document.write(document.getElementById(id).innerHTML);
}
}
neither works and I don´t know what I´m doing wrong, before I had a function only for the value of the element but want to be able to access other properties, the function that is currently working for me is:
function getTheValue(id) {
return document.getElementById(id).value;
}
But that only works to get the value of the object, what if I wanted to access the class_Name or innerHTML