How do I select an element with its name attribute in jQuery?

This question already has an answer here:

  • How can I select an element by name with jQuery? 15 answers

  • $('[name="ElementNameHere"]').doStuff();
    

    jQuery supports CSS3 style selectors, plus some more.

    See more

  • jQuery - Selectors
  • jQuery - [attribute=""] selector

  • You can use:

    jQuery('[name="' + nameAttributeValue + '"]');
    

    this will be an inefficient way to select elements though, so it would be best to also use the tag name or restrict the search to a specific element:

    jQuery('div[name="' + nameAttributeValue + '"]'); // with tag name
    jQuery('div[name="' + nameAttributeValue + '"]',
         document.getElementById('searcharea'));      // with a search base
    

    it's very simple getting a name:

    $('[name=elementname]');
    

    Resource:

    http://www.electrictoolbox.com/jquery-form-elements-by-name/ (google search: get element by name jQuery - first result)

    链接地址: http://www.djcxy.com/p/36258.html

    上一篇: jQuery:$(document).on(event,name as selector,function

    下一篇: 如何在jQuery中选择具有其名称属性的元素?