Reputation: 2343
from jQuery website:
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.
with version 1.7.1 i tried to change all my live() to on(), but none worked. Does anyone has any idea why?
this is how it gets called:
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
and this is one of the scripts that don't work:
$(".toBeSaved [col=ISRC] input").on('change',function() {
var pid = $(this).parent().parent().attr('primary_key');
$("[primary_key="+pid+"] [col=isrc_id] input").val('');
$("[primary_key="+pid+"] [col=isrc_id] input").css({'border':'1px solid red','background-color':'#e8b7cf'});
});
html:
<tr primary_key="44" class="toBeSaved">
<td col="ISRC" style="width: 91px; " class="editableCell"><input class="editableInput auto" type="text" undefined=""></td>
<td col="LineYear" style="width: 35px; " class="editableCell"><input class="editableInput " type="text"></td>
<td col="isrc_id" style="width: 41px; " class="editableCell"><input class="editableInput undefined" type="text" undefined="" readonly="readonly"></td></tr>
and can i just ask - why "-1"?? what exactly is wrong with my question?
Upvotes: 2
Views: 1941
Reputation: 97
Specific to the code submitted, as per the ramblings above;
Replace
$(".toBeSaved [col=ISRC] input").on('change',function() {
with
$(document).on('change','.toBeSaved [col=ISRC] input', function() {
Upvotes: 0
Reputation: 8433
Converting code from using .live
to .on
isn't just a case of replacing the calls to .live
with .on
calls. They accept different arguments, and are called on different selectors. For example, the old syntax:
$('a').live('click', function () {});
With .on
:
$(document).on('click', 'a', function () {});
This syntax gives you greater control and flexibility.
I would recommend reading the documentation: http://api.jquery.com/on/
And for information on converting to .on
from .live
:
http://api.jquery.com/live/
Upvotes: 7