This method is used to work with multiple functions i.e when you click on selected element first function will be fired and when you click on that selected element second function will be called and so on.
Syntax :
$(selector).toggle(function)
Parameter :
function : A function will fired every time on click the selected element.
HTML Code :
<html>
<head>
</head>
<body>
<p>Click me.</p>
</body>
</html>
jQuery Code :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").toggle(
function(){$("p").css({"color": "red"});},
function(){$("p").css({"color": "blue"});},
function(){$("p").css({"color": "green"});
});
});
</script>
Output :
Click me // when you click first time its color changed to red , on clicking second time its color change to blue, on third time it's color changed to green.
0 Comment(s)