Possible Duplicate:
Javascript fails to access a JSF component by calling through its id
It does not work when I try to retrieve an element using jQuery(idOfElement) when I use a variable but works fine if I use something like this: jQuery('#e') . How can I make it work correctly by passing a variable parameter ?
I am trying out the following piece of code:
function calculatePosition(idOfElement){
var $element = jQuery(idOfElement);
var offset = $element.offset();
var x = offset.left;
var y = offset.top;
....
....
}
Assuming you’re passing in the
idas a string like this:calculatePosition("randomID");Then you need to add the
#at the start of the jQuery selector:var $element = jQuery("#" + idOfElement);