0 votes
in JQuery by
What is the use of the toggle() method in JQuery?

1 Answer

0 votes
by
If there is a click event, toggle() attaches functions to toggle. So, on first click first action occurs, on second, second action and so on.

<button>Change my color on each click</button>

<script>

$(document).ready(function(){

$("button").toggle(

function(){$("button").css({"color": "blue"});},

function(){$("button").css({"color": "yellow"});},

function(){$("button").css({"color": "red"});

});

});

</script>
...