Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery, how to find an element by attribute NAME?

I found many example finding elements by attribute value BUT not with name. I want to find all elements (can be link, button, anything) with the attribute containing deleteuserid. I tried this:

console.log($('[deleteuserid!=""]'));

but this find "everything" which not even containing the deleteuserid attribute...

something like this: jQuery how to find an element based on a data-attribute value? expect that I dont have a concrete value (in other words, I want to find $("ul").find("[data-slide=*]");

like image 938
John Smith Avatar asked Feb 16 '16 08:02

John Smith


People also ask

How do I find an element by its attribute?

Use the querySelector() method to get a DOM element by attribute, e.g. document. querySelector('[data-id="first"]') . The querySelector method will return the first element in the document that matches the specified attribute.

How do you check if an element has an attribute in jQuery?

Using jQuery The idea is to use the . attr() method, which returns the attribute's value for an element if it is present and returns undefined if the attribute doesn't exist.

How get data attribute value in jQuery?

Answer: Use the jQuery attr() Method You can simply use the jQuery attr() method to find the data-id attribute of an HTML element.

What jQuery syntax selects HTML elements by a specific attribute and its value?

The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us").

How to select an element by name with jQuery?

- GeeksforGeeks 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 2 methods: We will understand both methods with the help of examples. The name attribute selector can be used to select an element by its name.

How do you use data attribute in jQuery?

Using data- as a prefix, you can add a data attribute to store some information within an element (any element). Now, how do you extract and use the data that are associated with the elements? Here, I’ll show you how using a simple jQuery method, you can find elements by its data attribute value. What is data attribute and how to use it?

How to select an element by the name attribute?

An element can be selected by the name attribute using 2 methods: The name attribute selector can be used to select an element by its name. This selector selects elements that have the value exactly equal to the specified value.

How to get the ID of an element in jQuery?

When we need to find a single and unique element at that time we can use jQuery get by element id. JQuery uses attr () method to find out the id of an element. The get by element id is a faster method because it directly calls the JavaScript engine.


2 Answers

Simply use deleteuserid instead of deleteuserid!="" like following.

console.log($('[deleteuserid]'));
like image 80
Ibrahim Khan Avatar answered Oct 16 '22 17:10

Ibrahim Khan


you can use the jquery attribute selector to search by name.

console.log($('[name="deleteuserid"]'));
like image 6
Neha Jain Avatar answered Oct 16 '22 15:10

Neha Jain