Welcome to findnerd, today we are going to discuss on toggle() method in jQuery.
Firstly let know what use of toggle() method
In the toggle() method, you can toggle between the hide() and show() methods in jQuery.
So we can say that toggle() method used to show elements are hidden and hidden elements are shown:
Syntax of toggle()
$(selector).toggle();
you can take reference of bellow example.
<html>
<head>
<!-- here call the jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();// call show() method on button
});
});
</script>
</head>
<body>
<button>Toggle Button</button>
<!-- here write paragrah and content on which you want use toggle() -->
<p>This is a example of toggle </p>
</body>
</html>
0 Comment(s)