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

Kyle picture Kyle · May 4, 2010 · Viewed 8.3k times · Source

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 :)

Answer

Tomalak picture Tomalak · May 4, 2010
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.