1 2 3 4 5 6 | < div id = "click-me-div" class = "switched-on" >
click me
</ div >
< br />
< button id = "switch-off" >Switch Off</ button >
< button id = "switch-on" >Switch On</ button >
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 | $( 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" );
}
});
});
|
|