Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Live() method in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 366
    Comment on it

    live() method:

    Live method is used to attach events to selected elements and also used to specify a function when the event occurs. It is similar to bind method but live method also attach event handler to elements generated using script while bind cannot.




    <!DOCTYPE html>
      <script src=""></script>
        .content{border:1px solid #333;padding:24px 7px;width:250px;margin-bottom:10px;}
        <div id="main-container">
            <p class="addlnk"><a href="javascript:void(0);" onclick="addDiv();">Add box</a></p>
            <div class="content">
              Use of live() method
        <script type="text/javascript">
                $(".content").live("mouseover", function()
                        $(this).css("background-color", "grey");
                }).live("mouseout", function()
                        $(this).css("background-color", "white");
        function addDiv()
                var div = $("<div></div>").addClass("content").text("Content generated using script");

    In the above example when we click on add box , a div will get added inside main-container div and also the mouseover and mouseout event will  get attached to new added div.

    The live() method was deprecated in jQuery version 1.7  and now we can use on() method for the same functionality.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: