I am new to javascript programming and have come across a strange situation. Examples will explain my problem better then my english will be able to.
What does work:
javascript code:
var element = "dividname";
function growElement(){
var h = document.getElementById(element).style.height;
document.getElementById(element).style.height = h + 20;
}
html code:<input type="button" value="button" onclick='growElement()' />
What I want to do that does not work:
javascript code:
function growElement(element){
var h = document.getElementById(element).style.height;
document.getElementById(element).style.height = h + 20;
}
html code:<input type="button" value="button" onclick='growElement("dividname")' />
does that make sense? I am unsure why the top one works and the lower one does not. When I debug with google chrome into the javascript, the variable "element" gets passed in correctly as "dividname" yet does not produce the same result when getting the element style information. I feel like I am missing something important but google searches haven't produced any helpful answers yet :( Any help will be greatly appreciated!


Sign In
Create Account


Back to top









