tags:

views:

44

answers:

1

Is it possible (using jQuery or otherwise) to set the style of a certain element to the :hover style defined in a stylesheet?

.regStyle {
   background-color: #000;
}

.regStyle:hover {
   background-color: #fff;
} 

Trying it out

$("#differentButton").click(function(){
    // this doesn't work 
    $("#someElement").addClass("regStyle:hover").remove("regStyle");
});
A: 

No. It'd be better to just give that state another class itself in the CSS and then use your method to add that class.

.regStyle:hover,
.regStyle.hover {
    css: properties;
    go: here;
}

$("#differentButton").click(function(){
    // this doesn't work 
    $("#someElement").addClass("hover");
});

EDIT: Okay, I take it back. There might be a way with .trigger('mouseOver'). To explain:

$('.regStyle').mouseOver( function() {
    $(this).css('css','property');
});

$('.otherElement').click( function() {
    $('.regStyle').trigger('mouseOver');
});

Completely untested and a little more cumbersome, but it might work.

dclowd9901