KW Online Tools Zone
Knowledge Walls
View All Tools Home
HOW TO TOGGLE SWITCH ON AND OFF EVENT HANDLERS IN JQUERY WITH EXAMPLE
[Jquery editor]
Run
Share Link
Clear
HTML [Ctrl+Enter] - to run
click me
Switch Off
Switch On
CSS [Ctrl+Enter] - to run
Jquery [Ctrl+Enter] - to run
$(function(){ $("body").on("click","#click-me-div[class*=switched-on]",function(){ alert("I am On!"); }); $("button").on("click","",function(event){ if ($(this).prop("id") == "switch-off"){ $("#click-me-div").removeClass("switched-on"); } else { $("#click-me-div").addClass("switched-on"); } }); });
OUTPUT
Copyright © 2021 Knowledge walls, All rights reserved
Copyright © 2021 Knowledge walls, All rights reserved