Fabian Schneider
Fabian Schneider

Reputation: 809

On div hover, return it's left attribute

I have 50 divs that have all the same class (.marker), and an id (#a1, #a2, ...).

Now I want, that if I hover over such a div a JavaScript function is called that returns the css-left attribute of the specific div:

function(divId){
return $(divId).css("left");
}

And I don't know how to do that without having to write a function call to every div. I thought of something with this.css("left"), that saves me typing work.

Thanks for your help in Advance...

Upvotes: 0

Views: 51

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

You can't return a value from a click handler. But, you can change your approach to changing a variable

var currentLeft;
$('.marker').hover(function(){
    currentLeft = $(this).css('left');
});

Upvotes: 3

Related Questions