Problem description
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").bind("click",function(){ $(this).slideToggle(); }); $("button").click(function(){ $("<p>This is a new paragraph.</p>"). insertAfter ("button"); }); }); </script> </head> <body> <div style="background-color:yellow"> <p>This is a paragraph</ p> <p>Please click any p element, it will disappear. Include this paragraph</ p> <button>Insert a new p element after this button</button> </div> </body> </html>
-
Click the button to insert a <p> Label and its contents -
click P label The current p element will be hidden or displayed
resolvent
$(document).ready(function(){ $("div").delegate("p","click",function(){ $(this).slideToggle(); }); });
$(selector).delegate(childSelector, event,data,function)
Reference article