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

dom, html, javascript, jquery

Solution

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?

Problem

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.

Original source