jQuery .hasClass() method fails for SVG elements

后端 未结 5 1816
挽巷
挽巷 2021-02-18 14:51

I have a set of SVG elements with the classes node and link. My program should detect whether an element has the node class or the l

5条回答
  •  长情又很酷
    2021-02-18 15:23

    Works. But be sure to close the function

    $(".node").hover(function(evt){
        console.log($(this).attr("class")); //returns "node"
        console.log($(this).hasClass('node')); //returns false
    }, function(){console.log("Done");});
    

    http://jsfiddle.net/X6BPX/

提交回复
热议问题