Toggle Div by id on paragraph click - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Toggle Div by id on paragraph click

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>toggle div on p click</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//w w w.  j a va 2  s.co m
$("#p1").on("click", function() {
  $("#d1").toggle();
});
    });

      </script> 
 </head> 
 <body> 
  <p id="p1"> click this to toggle div </p> 
  <div id="d1">
    div content 
  </div>  
 </body>
</html>

Related Tutorials