Home > Web Front-end > JS Tutorial > How to select elements by name attribute in jQuery

How to select elements by name attribute in jQuery

coldplay.xixi
Release: 2020-11-30 11:18:07
Original
11725 people have browsed it

How jQuery selects elements by name attribute: 1. Use the name attribute selector, the syntax is [[name="nameOfElement"]]; 2. Use javascript to get the element by name and pass it to jQuery.

How to select elements by name attribute in jQuery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

jQuery method of selecting elements by name attribute:

Method 1: Use the name attribute selector

name attribute selection can be used to select elements by their name attribute. This selector selects elements whose value is exactly equal to the specified value.

Syntax:

[name=“nameOfElement”]
Copy after login

Example:

How to select elements by name attribute in jQuery

Output:

How to select elements by name attribute in jQuery

Method 2: Use javascript to get elements by name and pass them to jQuery

You can use the javascript getElementsByName() method to select the required elements and pass them to jQuery functions for further use as jQuery objects

Syntax:

selector = document.getElementsByName(‘nameOfElement’);element = $(selector);
Copy after login

Example:

How to select elements by name attribute in jQuery

Output:

How to select elements by name attribute in jQuery

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to select elements by name attribute in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template