I’ve seen it’s jquery equivalent:
JavaScript
x
2
1
$('input[value="something"]');
2
But how do you select it using pure javascript (no jQuery).
Thanks for all the responses so far but I’m sure if it is working correctly, I need to change the value of the input into something else. I though I could do this by
JavaScript
1
2
1
<enter snippet to select element here>.value = "someOtherValue";
2
But it appears to be not that easy. Any ideas.
Advertisement
Answer
with ie6-ie7-ie8
JavaScript
1
10
10
1
function getInputsByValue(value)
2
{
3
var allInputs = document.getElementsByTagName("input");
4
var results = [];
5
for(var x=0;x<allInputs.length;x++)
6
if(allInputs[x].value == value)
7
results.push(allInputs[x]);
8
return results;
9
}
10
with modern browsers ie9+ (? not sure for ie9 actually) :
JavaScript
1
2
1
document.querySelectorAll("input[value=something]");
2