How to get nodeType using jquery

前端 未结 5 1399
借酒劲吻你
借酒劲吻你 2021-01-13 02:52

I want to get nodeType and then compare it to where it is text node or element node.





        
5条回答
  •  臣服心动
    2021-01-13 03:36

    To get the DOM Node you can use [0]:

    var mm = $(".jj")[0];
    if (mm.nodeType === 1) {
        // Node.ELEMENT_NODE
    }
    

    However,

    element will never be a text node and won't have a nodeValue.

    Text node is the first child of your

    element. So the following code will give you "value":

    alert(mm[0].firstChild.nodeValue);
    

提交回复
热议问题