Table event bindings mouseover,td and table all go through, but tr does not trigger bubbles. I don't know why.

table binds mouseover, but bubbles do not trigger tr, directly from td to table

related codes

< table id= "t" > < tr > < td > 1 < / td > < td > 2 < / td > < td > 3 < / td > < td > 6 < / td > < / tr > < tr > < td > 4 < / td > < td > 5 < / td > < td > 11 < / td > < td > 3 < / td > < / tr > < tr > < td > 7 < / td > < td > 8 < / td > < td > 9 < / td > < td > 10 < / td > < / tr > < / table >

< script >

document.getElementById("t").addEventListener("mouseover", function(e){
    if (e.target.nodeName.toLowerCase() == "td") {
        console.log("1")
    };
    if (e.target.nodeName.toLowerCase() == "tr") {
        console.log("2");
    };
    if (e.target.nodeName.toLowerCase() == "table") {
        console.log("3");
    }
}, false)

< / script >

the results are as follows

clipboard.png


modify the answer and use jquery to iterate through the .addEventListener event of tr
js. On this event in jquery.

getElementById ("t"). AddEventListener ("mouseover", function ()
change to
$("- sharpt tr"). On ("mouseover", function ()

)
<script type="text/javascript">
$("-sharpt").find("tr").each(function(){//tr
$("-sharpt tr").mouseover(function(){//mouseover
var index = $("-sharpt tr").index(this);
console.log(""+ index +"tr");
});
});
</script>


Menu