HI all! I have a doubt. I need to get an element via its id. I know i can use document.getElementById() or jquery selector, but i don´t want to use jquery or any other library. The idea is to build a component using just js and no libraries.
I got this situation, code generated by code:
<div id="objprop">
<div id="prop-header"><span>Mi Ventana</span></div>
<div id="prop_width" style="clear: both;">
<label style="margin-left: 7px; margin-bottom: 7px; float: left;">Width</label>
<input type="text" style="float: right; margin-right: 7px; width: 70px;" id="width">
</div>
<div id="prop_height" style="clear: both;">
<label style="margin-left: 7px; margin-bottom: 7px; float: left;">Height</label>
<input type="text" style="float: right; margin-right: 7px; width: 70px;" id="height">
</div>
<div id="prop_left" style="clear: both;">
<label style="margin-left: 7px; margin-bottom: 7px; float: left;">Left</label>
<input type="text" style="float: right; margin-right: 7px; width: 70px;" id="left">
</div>
<div id="prop_top" style="clear: both;">
<label style="margin-left: 7px; margin-bottom: 7px; float: left;">Top</label>
<input type="text" style="float: right; margin-right: 7px; width: 70px;" id="top">
</div>
</div>
so, let supose i want to set the value of input width id with. I´m not sure about using document.getElementById because may be other elements with same id in the html.
well that is my doubt
According to the specifications the id attribute of an element must be unique in a document. So as long as the document conforms to the specs you should have no problem using getElementById().