Is there a way to set the script for: before a button with a class .btn-expand transform style: rotate (360deg); ? I tried to just do it, but it does not work ..

$('.btn-expand').live('click', function(event) { $(this).css("transform", "rotate(360deg)"); }); 

Or what is another way out for this, since it cannot be done in this way?

Here is the complete code - >>> https://jsfiddle.net/pdgeatbs/

  • There was already such a question: they are pseudo elements and pseudo, that they cannot be accessed from javascript - Grundy
  • Pseudo-elements are unavailable from scripts - tutankhamun
  • 2
    Possible duplicate of the question: How to get right to: before with .css () - tutankhamun

2 answers 2

You need to do this:

1) add a class when clicking for the parent element

2) through css you do the necessary things like this:

 $('.btn-expand').live('click', function(event) { $(this).addClass("active"); }); .btn-expand.active:before { transform :rotate(360deg) } 

    You cannot manipulate :before , because pseudo-elements are not available from JavaScript. But you can add a new class with :before :

    CSS:

     .btn-expand.changed:after { transform :rotate(360deg) } 

    Js:

     $('.btn-expand').live('click', function(event) { $(this).toggleClass('changed'); });