Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript equivalent of $('input[name$="value"]') in jQuery?

How can I get an input element whose name attribute ends with a particular value using just javascript?

I found this $('input[name$="value"]') method available in jQuery.

Is there a function like that available in javascript? I cannot use jQuery for some reason.

like image 967
Vigneshwaran Avatar asked Apr 26 '12 14:04

Vigneshwaran


People also ask

How do you input a name in JavaScript?

In JavaScript, we can get user input like this: var name = window. prompt("Enter your name: "); alert("Your name is " + name); The code above simply prompts the user for information, and the prints out what they entered in.

What is the equivalent of on in jQuery to JavaScript?

In jQuery, you can listen to events for dynamically added elements using the on() function. The equivalent in JavaScript is addEventListener() function.

How can I select an element by name with jQuery?

Answer: Use the Attribute Selector You can use the CSS attribute selectors to select an HTML element by name using jQuery. The attribute selectors provide a very flexible and powerful mechanism for selecting elements.


1 Answers

I'm surprised that nobody has mentioned this yet. Have you tried:

var elements = document.querySelectorAll('input[name$="value"]');

This will only work if the browser supports the querySelectorAll method but it is what jQuery uses underneath if support is found.

Here's the table that lists browser support for the method:

When can I use querySelector/querySelectorAll?

like image 123
Justin Niessner Avatar answered Oct 20 '22 09:10

Justin Niessner