hi friends. i need a help i want to disply a div below of a text box. i use this script to do it : but div displaying extractly top on text box , so change it like below but this time it's nt working . what is the mistake ? ** i am using ' position:absolute; ' for div
Try: document.getElementById('fi').style.top = String(parseInt(document.getElementById('textfield').style.top) + 14) + 'px'; Code (markup):
The code I suggested would work if the script had previously set the 'top' setting on the element 'textfield' or if the tag for 'textfield' has a 'style' attribute that includes the 'top' setting. If you haven't set a specific value of 'top' for 'textfield', you can try calling getComputedStyle and parsing the information, but it's easier if you just set the value in the first place so JavaScript can see and work with it. Either add a 'style' attribute to the tag or set the value using JavaScript. Good luck!
You cannot add the top style attribute to the div element without first changing it's position attribute to either absolute or relative: document.getElementById('fi').style.position = 'absolute'; document.getElementById('fi').style.top = parseInt(document.getElementById('textfield').style.top) + 14 + 'px'; Code (markup): As you see, I also added parseInt() and (+ 'px'), that is because, if style.top is of string data type in pixels, you must have only the integer to add it to 14. I assume the 14 is the height of the textfield, I believe you could also do: document.getElementById('fi').style.position = 'absolute'; document.getElementById('fi').style.top = parseInt(document.getElementById('textfield').style.top) + document.getElementById('textfield').clientHeight + 'px'; Code (markup):