How can I get name of element with jQuery?

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

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

7条回答
  •  北海茫月
    2021-01-30 08:22

    Play around with this jsFiddle example:

    HTML:

    Hello, world!

    jQuery:

    $(function() {
        var name = $('#foo').attr('name');
    
        alert(name);
        console.log(name);
    });
    

    This uses jQuery's .attr() method to get value for the first element in the matched set.

    While not specifically jQuery, the result is shown as an alert prompt and written to the browser's console.

提交回复
热议问题