Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery and the :active selector

This is my code:

$('#ss a:active').parent().addClass('ss-active');

I guess you can tell from my code what I want to do, but it's not working, how can I do this? and I also want when the user removes the mouse from the button to come back to normal state, what I mean by: "the user removes the mouse from the button" is that the user can only hold click on the button for a while and it should see the:active statement.

I can't do this with css because I need the parent of that <a>.

//Here it is, how I got it working!

    $('#solicita a').mousedown(function() {
    if($(this).parent().hasClass('solicita-hover'))
    {
        $(this).parent().removeClass('solicita-hover');
        $(this).parent().addClass('solicita-active');
    }
}).mouseleave(function() {
    $(this).parent().removeClass('solicita-active');
});
like image 451
Uffo Avatar asked Aug 30 '26 07:08

Uffo


1 Answers

Try using the mousedown() event:

$('#ss a').mousedown(function() {
 $(this).parent().addClass('ss-active');
}).mouseup(function() {
 $(this).parent().removeClass('ss-active');
});
like image 89
twerq Avatar answered Sep 02 '26 14:09

twerq