Adding hover CSS attributes via jQuery/Javascript

后端 未结 4 607
离开以前
离开以前 2020-12-06 09:10

Some CSS styles need to be applied to an element on hover, and CSS styles have to be applied using javascript/jquery directly and not through stylesheets or $(this).ad

4条回答
  •  -上瘾入骨i
    2020-12-06 09:50

    I find using mouseenter and mouseleave to be better than hover. There's more control.

    $("#somecontent").mouseenter(function() {
        $(this).css("background", "#F00").css("border-radius", "3px");
    }).mouseleave(function() {
         $(this).css("background", "00F").css("border-radius", "0px");
    });
    

提交回复
热议问题