jQuery .live function removed in V 1.9. What is the best replacement for .live function ?


Read {count} times since 2020

As of jQuery version 1.9, the .live function has been removed which means it is no longer available to use. Instead of this function you can use .on function which also has the same function as .live

Both of them attach an event handler for all elements which match the current selector, now and in the future.

Since .live has been removed you can use .on function. Here’s how we should do it.
Replace .live function with .on. It’s that simple.
Example:

<div class="container" style="background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
  <blockquote class="tr_bq">
    <p>
      <span style="font-family: Times, Times New Roman, serif;">$(<span class="string" style="box-sizing: border-box; color: #dd1144;">"<span style="color: red;">#dataTable tbody tr</span>"</span>).live(<span class="string" style="box-sizing: border-box; color: #dd1144;">"<span style="color: red;">click</span>"</span>, <span class="keyword" style="box-sizing: border-box; font-weight: bold;">function</span>(event){<br /><span style="background-color: white;"> alert($(<span class="keyword" style="box-sizing: border-box; color: red; font-weight: bold;">this</span>).text());</span><br /><span style="background-color: white;">});</span></span>
    </p>
  </blockquote>
</div>

With :

$("#dataTable tbody tr").on("click", function(event){
alert($(this).text());
});

Use a software such as regexxer to replace all .live( word with .on( word.

Show Comments