[Javascript] To DOM or not -- calendar popup

Nick Fitzsimons nick at nickfitz.co.uk
Wed Mar 29 14:16:10 CST 2006


Steve Clay wrote:
> Wednesday, March 29, 2006, 1:58:48 PM, Bill Moseley wrote:
> 
>>2) or in the script search for the input field and then append the
>><img>  to the field's parent node list?[1]
> 
> 
> var myInput = document.getElementById('myInput');
> var myImg = document.createElement('img');
> 
> if (myInput.nextSibling) {
>     myInput.parentNode.insertBefore(myImg, myInput.nextSibling);
> } else {
>     myInput.parentNode.appendChild(myImg);
> }

Steve: there's no need for the if/else test for nextSibling; if the 
second argument to "insertBefore" is null then it acts like 
"appendChild" anyway. See:
<http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core.html#ID-952280727>

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list