There are my codes:
Jquery
$(function() {
$("#evtTarget").bind("mouseover",highlighted);
$("#evtTarget").bind("mouseleave",highlighted);
$("#evtTarget").bind("click",function(){
$("#evtTarget").unbind("mouseover",highlighted);
$("#evtTarget").unbind("mouseleave",highlighted);
$("#evtTarget").html("Off.Click for On.");
});
});
function highlighted(evt){
$("#evtTarget").toggleClass("highlighted");
}
Html
<h1>Binding Event Example</h1>
<div id="evtTarget" class="normal">On. Click for Off.</div>
Css
normal {
width:300px;
height:200px;
background-color:red;
font-size:18pt;
color:black;
}
.highlighted {
background-color:white;
}
If you mouseover evtTarget id paragraph highligt. And if you click evtTarget id highlighting will be off.
But I want to if user click secondly highlighting is on.
How can i do this?
You could use the
.datamethod (api) to save the whether or not highlighting is on: