So my question is: is there a way how to replace repetitive document.getElementById? as I have a lot of them and as many may agree, the code does not look nice like this.
Below is a sample of what I have in my code.
document.getElementById('FieldAddClient').hidden = true;
document.getElementById('FieldAddClient').disabled = true;
document.getElementById('AddingClientTitle').hidden = true;
document.getElementById('AddingClientDesc').hidden = true;
document.getElementById('DuplicatingClientTitle').hidden = false;
document.getElementById('DuplicatingClientDesc').hidden = false;
Make 'em variables:
var my_el = document.getElementById('selector');
my_el.style.hidden = true;
Make a helper function:
function el_by_id(s)
{
return document.getElementById(s);
}
el_by_id('selector').style.hidden = true;
Make a deeper helper function:
function style(s, p, v)
{
document.getElementById(s)[p] = v;
}
style('selector', 'hidden', true);
or, use jQuery...
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