checkall function does not work well with jquery1.9.1

checkall function does not work well with jquery1.9.1

ustbustb Posts: 3Questions: 0Answers: 0
edited April 2013 in General
my codes:
[code]
$(function(){
var oTable = $('#dyntable').dataTable({
"sPaginationType": "full_numbers",
//"bStateSave": true,
"aoColumnDefs": [

"bSortable": false,
"bSearchable": false,
"aTargets": [0],
"sClass": "center",
"mRender": function(data, type, full){
return '';
}
},
],
"bProcessing":true,
"bServerSide": true,
"sAjaxSource": "/user/sellerList"
});

/// check all
$('.stdtable').on("click", '.checkall', function(){ // just work once
//$('.stdtable .checkall').live("click", function(){// .live() is deprecated, it work well with jquery1.7.1
$('input', oTable.fnGetNodes()).attr('checked',this.checked);
});
})
[/code]

.live() is deprecated in jquery1.7+ but .on() does not work well.
Is there a good way to solve the version problem?

Replies

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    The `on` method works just fine. Try `$('body').on('click', '.checkall', ... );` - my guess is that the selector is wrong. But we'd need a test case to know for sure - I'm just guessing at the moment.

    Allan
  • ustbustb Posts: 3Questions: 0Answers: 0
    Thanks Allan.
    It is very strange.When I first click the ".chechall" element it works fine however the second time to failure.
    I change the selector to "body" then the result is the same as before.
    I use firebug to check the DOM then find that the checkbox is signed 'check="checked"'.It is right but can't be shown on page.Is there a cache?I don't know.
  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    It sounds like the delegated event isn't being attached. As I said before, I was guessing somewhat. We need a test case to actually be able to help.

    Allan
  • ustbustb Posts: 3Questions: 0Answers: 0
    Thanks Allan. I find the way to solve the problem.
    [code]
    $('input', oTable.fnGetNodes()).prop('checked',this.checked);// change .attr() to .prop()
    [/code]
This discussion has been closed.