
Originally Posted by
raman19
im pretty new at this. Can someone please explain why this does not work:
function Slide(elementInside)
{
slider = document.getElementById(elementInside);
var sliderHeight;
sliderHeight = slider.style.height;
}
I want to be able to capture the height of any div that is passed into this function. I have the javascript, html and css in 3 different files..
Many thanks.
The code you've provided seems to be fine except some small things like introduced an item without declaring it. Unlike you've mentioned it will not check whether the send element ID belongs to a div block or not it will try to get an element with the provided ID whether it is div, span, p or any other elements.
I've changed the code a bit so that it will not perform any incorrect operation if the mentioned element is not present
Code:
function Slide(elementInside){
var slider = document.getElementById(elementInside);
if(slider){
var sliderHeight = slider.style.height;
alert(sliderHeight); //At this point you can return the height to the calling point of this function if you want.
}
return;
}
You can shorten the length of the above mentioned function if you want but I thought it would be better if you consider that before doing so.
Bookmarks