Home >>jQuery Tutorial >jQuery toggle() Property

jQuery toggle() Property

jQuery toggle() Property

jQuery toggle() method in jQuery is used to add two or multiple functions to toggle between for the click event for the selected elements.

Syntax:

$(selector).toggle(function)

Parameter Values

Parameter Description
function It is a required parameter which is used to run a function every time when the selected element is clicked

Here is an Example of jQuery toggle() Method:


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".txt").toggle(
function(){$(".txt").css({"color": "orange"});},
function(){$(".txt").css({"color": "lightgreen"});},
function(){$(".txt").css({"color": "purple"});},
function(){$(".txt").css({"color": "pink"});
});
});
</script>
</head>
<body>
<p class="txt" style="font-size:35px">Click Here</p>
</body>
</html>

Output:

Click Here


No Sidebar ads