Hi,
I have a lot of div's and I want to fade this one who is hovered.
How i can get the id of the hovered div?
Is there anyway to do that except calling function(and sendind the id) with "onmouseover"?
Thanks!
views:
518answers:
2
+1
A:
try something like
$(".classes").mouseover(function() {
$(this).function();
};
to get the ID of an element you use the attr function
$('.name').attr('id');
Terw
2009-12-12 17:36:08
A:
You could set a class to flag the divs after you applied the animation so you can easily identify hovered divs.
(function($){
$.fn.extend({
myDivHover: function(){
var $set = $(this);
return $set.each(function(){
var $el = $(this);
$el.hover(function(){
fadeOutAnimation( $el, $set );
}, function(){
fadeInAnimation( $el );
});
});
}
});
function fadeOutAnimation( $target, $set ){
// Revert any other faded elements
fadeInAnimation( $set.filter('.hovered') );
// Your fade code here
...
...
// Flag
$target.addClass('hovered');
}
function fadeInAnimation( $target ){
// You revert fade code here
...
...
// Unflag
$target.removeClass('hovered');
}
})(jQuery);
// Apply it to the divs with XXX class
$('div.XXX').myDivHover();
// Select hovered item
var theID = $('div.XXX').filter('.hovered').attr('id');
Hope it helps :)
Kindred
2009-12-12 18:54:25