jQuery live() with click event

Description

jQuery live() with click event

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
</script>// w  w  w.  jav a2  s. c  o m
<script>
$(document).ready(function(){
  $("p").live("click", function(){
    $(this).slideToggle();
  });
  $("button").click(function(){
    $("<p>new added</p>").insertAfter("button");
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

<p>This is a paragraph.</p>
<p>Click any p element to make it disappear. Including this one.</p>
<button>Insert a new p element after this button</button>
</body>
</html>



PreviousNext

Related