document.getElementById doesnt work with "input id", how can I do it? [+Greasemonkey]
I have this line on a website
<input type="text" autocomplete="off" value="" maxlength="20" class="shipBox" name="firstName" id="firstName">
and I want my greasemonkey to automatically fill this...
I'm trying this but had no success
document.getElementById("firstName").setAttribu开发者_StackOverflow社区te("autocomplete", "on");
document.getElementById("firstName").value = "Bruno"
What you're doing is basically the correct way.
The usual reaqson for this not working is a second element with the same ID somewhere in the document.
By the way, setAttribute
is not the recommended way of setting an attribute in HTML, as I've been reminded today. A simple ...getElementById("firstName").autocomplete = 'on'
will do.
精彩评论