jQuery noob: change border color of element on hover of another element

不问归期 提交于 2019-12-14 03:21:58

问题


I'd try to explain what I mean, but there is an easier way: click here for jsfiddle example.

Basically I want the border color of the div rfrsh_btn to change when productOptionsMenu is hovered over.

I'm using jQuery with the .noConflict var because this site also uses Prototype.

jQuery:

var $j = jQuery.noConflict();

$j(".productOptionsMenu").hover(
    function () {
        $j(#rfrsh_btn).css({"border-color":"#85c222"});
    };
);

Thanks :)


回答1:


var $j = jQuery.noConflict();

$j(".productOptionsMenu").hover(
    // hover begin (mouse-in)
    function () {
        $j("#rfrsh_btn").css({"border-color": "#85c222"});
    },
    // hover end (mouse-out)
    function () {
        $j("#rfrsh_btn").css({"border-color": ""});
    }
);

Instead of css() I recommend using addClass() and removeClass(), respectively.




回答2:


looks correct to me, maybe just add the missing quotes in

$j("#rfrsh_btn").css({"border-color":"#85c222"});



回答3:


Try this:

$j('.productOptionsMenu ').mouseover(function(){
  $j("#rfrsh_btn").css({"border-color":"#0000ff"});
});


来源:https://stackoverflow.com/questions/2764147/jquery-noob-change-border-color-of-element-on-hover-of-another-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!