Wednesday, 15 May 2013

javascript - Delegation creates malfunction -



javascript - Delegation creates malfunction -

$('.settings').hover(function(){ $(this).addclass('current'); changecolor(); },function(){ $(this).removeclass('current'); });

adds class "current" div.

function changecolor(){ $(document).on('mouseenter','.current',function() { $('.current').css("cursor","pointer"); $('#this').css('background-color', $("div.current > div:nth-child(1)").attr('id')); $('#this1').css('background-color', $("div.current > div:nth-child(2)").attr('id')); $('#this2').css('background-color', $("div.current > div:nth-child(3)").attr('id')); }).on('mouseleave', '.current', function() { $('#this').css('background-color', currentcolor); $('#this1').css('background-color', currentcolor1); $('#this2').css('background-color', currentcolor2); }) };

changes color of several divs when "current" div hovered. problem when seek alter first code into:

$(document).on('mouseover','.settings',function(){ $(this).addclass('current'); }).on('mouseleave','.settings',function(){ $(this).removeclass('current'); });

the sec code not function anymore.

javascript jquery

No comments:

Post a Comment