How can I get name of element with jQuery?

前端 未结 7 903
执笔经年
执笔经年 2021-01-30 07:49

How can I get name property of HTML element with jQuery?

7条回答
  •  不思量自难忘°
    2021-01-30 08:14

    To read a property of an object you use .propertyName or ["propertyName"] notation.

    This is no different for elements.

    var name = $('#item')[0].name;
    var name = $('#item')[0]["name"];
    

    If you specifically want to use jQuery methods, then you'd use the .prop() method.

    var name = $('#item').prop('name');
    

    Please note that attributes and properties are not necessarily the same.

提交回复
热议问题