I have a hidden input field:
<input type="hidden" id="entity__token" name="entity[_token]" value="SOMEVALUE" />
In my HTML the value of 'entity' in the attributes name
and id
could be anything, for example:
<input type="hidden" id="example__token" name="example[_token]" value="SOMEVALUE" />
I try to get the value of any kind of input field where the id ends with __token
.
After reading this question I tried:
var hiddenField = document.querySelector("[id^='__token']");
console.log(hiddenField.value);
That didn't work. I am looking for a solution without any jQuery.