Attach event handler for new added element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:live

Description

Attach event handler for new added element

Demo Code

ResultView the demo 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  .j av  a2s. c  o  m
<script>
$(document).ready(function(){
    $("p").live("click", function(){
        $(this).slideToggle();
    });
    $("button").click(function(){
        $("<p>This is a new paragraph.</p>").insertAfter("button");
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<p>Click any p element to make it disappear.</p>

<button>Insert a new p element after this button</button>

</body>
</html>

Related Tutorials