0

I have a table with a menu hidden in a cell that that I expand using slideToggle(). This menu has a few <img> that onclick= call a function and passed the element and a number. Now I'm trying to get the position of the element that made the call so I can dynamically create an overlay <div>. The problem is that I am not getting the position values and I don't know why. HERE is a small example of what I am trying to do. Can anyone help?

4

1 回答 1

0

I believe the issue is your use of $(this). You are passing the element that was clicked into your function so you need to use that instead. I have also updated your alert to explicitly output the left offset as offset would just return an object. You could instead use console.log to be able to inspect the returned object (in a browser like chrome):

window.somefunc = function(el,id){
    var pos = $(el).offset();
    alert(pos.left);
}

I have updated your JSFiddle here: http://jsfiddle.net/gRfnb/22/

于 2012-10-29T17:03:28.770 回答