We can toggle a block of content using toggle() property in jquery. When user clicking button or some other event we will implement the toggle using class propery or id of the element. Below example I will show you how to toggle.
Example:
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>to toggle the divelement using class property in jquery</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#animate').click(function () {
$('.box').toggle();
});
});
</script>
<style type="text/css">
.box {
background-color: purple;
margin: 20px;
padding: 10px;
width: 10em;
color: white;
}
.button {
background-color: purple;
color: white;
margin: 20px;
padding: 10px;
}
</style>
</head>
<body>
<div class="content">
<h2 style="color: #325696">toggle the div element using class property in jquery</h2>
<input type="button" id="animate" class="button" value="animate" />
<div class="box">
<p>
click on the animate button and see what is happening.
</p>
</div>
</div>
</body>
</html>
Post your comments / questions
Recent Article
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
Related Article