tags:

views:

48

answers:

2
function getLeftPos(elm){
  var left = 0;
  while(elm){
    left += elm.offsetLeft;
    elm= elm.offsetParent;
  }
  return left;
}

How come this doesn't work?

getLeftPos(document.getElementById("#frame"));

If I alert(elm) inside that function, it is NULL.

+8  A: 

Don't put the # in the id.

getLeftPos(document.getElementById("frame"));
Marius
+4  A: 

Another viable answer to your question "how come this doesn't work" is:

Javascript != JQuery

Not trying to be snarky but its a really important thing to remember.

For core Javascript documentation a good resource in general is developer.mozilla.org and for getElementById in particular

George Jempty
jQuery *is* JavaScript.
Gumbo
... yet learning to call dom els and perform pretty css tricks clearly goes far in toning javascript skills.
Dimitar Christoff