In this tutorial I use Visual Studio Code for Text Editor and Google Crome for Browser
In this tutorial we will create a button that when we click it will appear the content and when we click for other time the content will be hide.
toggle.html<html>
<head>
<title>Toggle</title>
</head>
<body>
</body>
</html>
<button>Hide/Show</button>
<p> element. You can create other element as you want.<p>Seamlessly sync your projects and <br> contributions with the Github feed</p>
<button> and <p> element.<button id="toggle">Hide/Show</button>
<p id="content"> Seamlessly sync your projects and <br> contributions with the Github feed</p>
<head> element. Where we get jQuery file or CDN ? you can visit here for detail. In this tutorial I use jQuary Google CDN.<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script> Tag before </body> . Or you can also add the Script in external js file<script></script>
<script> tag. $(document).ready(function(){
...
});
$("#toggle").click(function(){
});
#toggle: the id of button .click(): click event.function(){}: open the function
<p> element we need use the toggle() method. How to use it ? first call the <p> element by id then add the toggle() method like this$("#content").toggle();
#content: The ID of<p>element.toggle()method to hide and show and element.
<p> element hide and show.The full code :
<html>
<head>
<title>Toggle</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<button id="toggle">Hide/Show</button>
<p id="content"> Seamlessly sync your projects and <br> contributions with the Github feed</p>
<script>
$(document).ready(function(){
$("#toggle").click(function(){
$("#content").toggle();
});
});
</script>
</body>
</html>