jquery nodename returning undefined

后端 未结 2 1086
醉梦人生
醉梦人生 2021-01-01 09:04

This code isn\'t for anything in particular. I\'m just trying to successfully get the tagName or nodeName of an element. However, when I run the following code, I always get

相关标签:
2条回答
  • 2021-01-01 09:47

    Use the prop() of jQuery:

    alert($('#last').prop("nodeName"));
    
    0 讨论(0)
  • 2021-01-01 09:50

    You are trying to access a non-member of the jQuery object. Use one of these DOM element accessors to retrieve these properties:

    $( '#last' ).get(0).nodeName

    OR

    $( '#last' )[0].nodeName

    OR

    document.getElementById( 'last' ).nodeName

    0 讨论(0)
提交回复
热议问题