views:

33

answers:

2

I am taking the value of a select element and trying to modify it so that I can have access to the onscreen preview element that the select item represents. Here is the first part of the code...

$("#single_area_select").change(function(){
        var $element = '#preview_' + $("#single_area_select").val().toLowerCase();
        elementChangedOrSelected($element);
    });

And the critical part of the elementChangedOrSelected() method...

function elementChangedOrSelected(element){
    element = '$("' + element + '")';
    alert(element);
    var position = element.position();
    alert(position);

My first alert makes it look like i've got it right (ie, $("#preview_title") ), but the second alert doesn't make an appearance which tells me that the position query is failing. Can anyone see something that I can't?

+3  A: 
function elementChangedOrSelected(element){
    element = $(element);
    alert(element);
    var position = element.position();
    alert("left: " + position.left + ", top: " + position.top);
}
dejavu
Yeah this. `'$("' + element + '")'` returns a string, which would not have a position method.
Squeegy
i knew i'd feel stupid. thanks!
JakeVA
A: 

you just need to do this:

position = $(element).position();
Patricia