jQuery on()
with mouse over and mouse out event
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>//w w w . j av a2 s .co m <script> $(document).ready(function(){ $("p").on("mouseover mouseout", function(){ $(this).toggleClass("intro"); }); }); </script> <style> .intro { font-size: 150%; color: red; } </style> </head> <body> <p>Move the mouse pointer over this paragraph.</p> </body> </html>