javascript - jQuery .bind() not working properly - Stack Overflow

I'm attempting to bind functions to these events using jQuery:$("#cmplist tr").bind(

I'm attempting to bind functions to these events using jQuery:

$("#cmplist tr").bind('onmouseover', function(){
    console.log('1');
});

$("#cmplist tr").bind('onmouseout', function(){
    console.log('2');
});

$("#cmplist tr").bind('click', function(){
    console.log('3');
});

However none of them seem to work. I'm reasonably sure my selectors are correct since when I enter into the console $("#cmplist tr") it returns:

[tr, tr#survey3, tr#survey20, tr#survey22, tr#survey26, tr#survey28, tr#survey29, tr#survey30, tr#survey33, tr#survey34, tr#survey6, tr#survey19, tr#survey14, tr#survey32, tr#sweepstakes5, tr#sweepstakes9, tr#coupons5, tr#freesample4, tr#freesample5, tr#freesample6, tr#freesample7, tr#gifts3, tr#gifts4, tr#polls2, tr#polls5, tr#polls6, tr#quiz8, tr#trivia4, tr#photo6, tr#photo10, tr#photo11, tr#photo12, tr#photo13, tr#photo15, tr#photo16, tr#photo17, tr#video4, tr#iframe2, tr#iframe4]

Am I missing something about how jQuery events work?

I'm attempting to bind functions to these events using jQuery:

$("#cmplist tr").bind('onmouseover', function(){
    console.log('1');
});

$("#cmplist tr").bind('onmouseout', function(){
    console.log('2');
});

$("#cmplist tr").bind('click', function(){
    console.log('3');
});

However none of them seem to work. I'm reasonably sure my selectors are correct since when I enter into the console $("#cmplist tr") it returns:

[tr, tr#survey3, tr#survey20, tr#survey22, tr#survey26, tr#survey28, tr#survey29, tr#survey30, tr#survey33, tr#survey34, tr#survey6, tr#survey19, tr#survey14, tr#survey32, tr#sweepstakes5, tr#sweepstakes9, tr#coupons5, tr#freesample4, tr#freesample5, tr#freesample6, tr#freesample7, tr#gifts3, tr#gifts4, tr#polls2, tr#polls5, tr#polls6, tr#quiz8, tr#trivia4, tr#photo6, tr#photo10, tr#photo11, tr#photo12, tr#photo13, tr#photo15, tr#photo16, tr#photo17, tr#video4, tr#iframe2, tr#iframe4]

Am I missing something about how jQuery events work?

Share Improve this question asked May 30, 2011 at 3:15 Casey FlynnCasey Flynn 14k26 gold badges108 silver badges196 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Drop the "on" from your event names. Also I think the hip thing to do nowadays is to use "mouseenter" and "mouseleave" with jQuery event handlers. Those events are "normalized" by the library so as to make everything more reliable in the face of quirky browser behavior.

Also, make sure you do your binding in a "ready" handler, unless you're confident you've got an alternative, equally effective solution:

$(function() {

  // your event binding stuff here

});

try this:

$(function(){

    $("#cmplist tr").bind('mouseover', function(){
        console.log('1');
    });

    $("#cmplist tr").bind('mouseout', function(){
        console.log('2');
    });

    $("#cmplist tr").bind('click', function(){
        console.log('3');
    });

});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743718232a4495362.html

相关推荐

  • javascript - jQuery .bind() not working properly - Stack Overflow

    I'm attempting to bind functions to these events using jQuery:$("#cmplist tr").bind(

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信