jQuery attr('onclick')

前端 未结 4 2012
Happy的楠姐
Happy的楠姐 2020-12-15 03:45

I\'am trying to change \"onclick\" attribute in jQuery but it doesn\'t change, here is my code:

$(\'#stop\').click(function() {
     $(\'next\').attr(\'oncli         


        
4条回答
  •  自闭症患者
    2020-12-15 04:13

    Do it the jQuery way (and fix the errors):

    $('#stop').click(function() {
         $('#next').click(stopMoving);
         // ^-- missing #
    });  // <-- missing );
    

    If the element already has a click handler attached via the onclick attribute, you have to remove it:

    $('#next').attr('onclick', '');
    

    Update: As @Drackir pointed out, you might also have to call $('#next').unbind('click'); in order to remove other click handlers attached via jQuery.

    But this is guessing here. As always: More information => better answers.

提交回复
热议问题