codice:<!DOCTYPE html><html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#mioDIV").toggleClass("redBG"); }); }); </script> <style type="text/css"> #mioDIV { width:100px; height:100px; } .greenBG { background:green; } .redBG { background:red; } /* IMORTANTE! la classe redBG va definita DOPO greenBG */ </style> </head> <body> <div id="mioDIV" class="greenBG"></div> <button>Toggle class for element</button> </body> </html>


Rispondi quotando
