Search code examples
buttongetelementbyiddashcode

Why is my button not an object? Is it because it is in the header?


When I run this code

var button=document.getElementById("button")

if (navigator.userAgent.indexOf('iPhone') != -1)
{
button.style.left = 250;
}

The error is result of expression is not an object. The object "button" is in the css file and it is the only one named button. What am I doing wrong? Does it have something to do with the button being in the header? I'm using dashcode.


Solution

  • Try

    var button=document.getElementById("button").object
    

    getElementById gives you the HTML DOM node for the button; you have to access its object to do all of the fancy Dashcode stuff to it. (I stumbled around with the same question for a while!)