live() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:live

Description

The live() method was deprecated in jQuery version 1.7, and removed in version 1.9. Use the on() method instead.

The live() method attaches event handlers for both current and FUTURE elements.

Syntax

$(selector).live(event,data,function);
Parameter Require Description
event Required.one or more events to attach to the elements.
data Optional. additional data to pass along to the function
function Required.the function to run when the event occurs

The following code shows how to Hide or show a <p> element when a button is clicked:

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  ava 2  s.  c  o m
<script>
$(document).ready(function(){
    $("button").live("click", function(){
        $("p").slideToggle();
    });
});
</script>
</head>
<body>

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

<button>Click me!</button>
<br><br>

</body>
</html>

Related Tutorials