How to use the name selector method In JQuery

The name attribute selector can be used to select an element by its name. This selector selects elements that have a value exactly equal to the specified value.

Syntax:

[name="nameOfElement"]

Example: This example illustrates the use of the name selector method to select the specific element.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
          How to select an element by name with jQuery?
      </title>
</head>
 
<body>
    <center>
        <h1 style="color: green">w3wiki</h1>
        <b>How to select an element by name with jQuery?</b>
        <p>
            The textbox below has the <b>name attribute 'address'.</b>
          <form>
              <textarea rows="4" cols="40" name="address"></textarea>
          </form>
        </p>
 
        <p>
            The textbox below has the
              <b>name attribute 'area'.</b>
        <form>
            <input type="text" name="area">
        </form>
        </p>
 
        <p>Click on the button to hide the input with
            the name 'area'</p>
 
        <button onclick="selectByName()">
            Click to hide the area input
        </button>
        <script src=
"https://code.jquery.com/jquery-3.3.1.min.js">
        </script>
        <script type="text/javascript">
            function selectByName() {
                element = $('[name="area"]');
 
                //hide the element
                element.hide();
            }
        </script>
    </center>
</body>
 
</html>


Output:

name selector Method

How to select an element by name with jQuery ?

In this article, we will learn to get the selected element by name in jQuery. An element can be selected by the name attribute using two methods:

Table of Content

  • Using the name selector method
  • Using JavaScript to get the element by name and pass it on to jQuery

We will understand both methods with the help of examples.

Similar Reads

Using the name selector method

The name attribute selector can be used to select an element by its name. This selector selects elements that have a value exactly equal to the specified value....

Using JavaScript to get the element by name and pass it on to jQuery

...

Contact Us