Change CSS with jQuery

0

I have already changed css with jQuery, but I would like to test a feature, in onclick it add a css but a :before field how could I do that?

Working Code

$j("#nome-login-mobile").click(function(){
    if ($j('#options-menu').is(':visible')) {
        $j('#options-menu').hide();
        $j('.nome-login-mobile').removeClass('changed');
    } else {
        $j('.nome-login-mobile').toggleClass('changed');
        $j('#options-menu').show();
    }    
})
    
asked by anonymous 21.09.2017 / 18:43

2 answers

1

Use addClass , or toggleClass to draw and for each click

$('div').on('click', function() {
    $(this).addClass('before');
});
div.before:before {
    content: "before adicionado ";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div>adicionar before</div>
    
21.09.2017 / 18:53
1

How can you post an example of how you want it?

I believe something like:

$(document).on('click', '#efeito', function(){ //Ação executada no evento de clique no elemento com ID = "efeito"
$('#teste').css("background-color", "yellow"); //Insere fundo amarelo no elemento com ID = "teste"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="teste">xyz</div>
<a herf="#" id="efeito">Mudar Estilo</a>
    
21.09.2017 / 18:58