I have an element in an webpage
id="1253~~0~0~506~13501157_txtValue"
I want to search all element matches beginning with this value 1253 and it should be filled up the value test
For this I am using this following code but it isnt working
document.querySelector('[id^ ='1253']').value = test
Please guide me as to where I am going wrong Thanks in advance. -Vicky.
Your selector is good but you should either use double quotes (") and single quotes (') or escape your inner single quotes.
Also, if test is not a variable you should surround it with quotes : "test".
As pointed out by @adiga, if you want to match all elements whose id begins with "1253", you should use querySelectorAll() and loop through the results.
document.querySelector("[id^='1253']").value = "test";
//the following line is equivalent
//document.querySelector('[id^=\'1253\']').value = "test";
<input type="text" id="1253~~0~0~506~13501157_txtValue" />