Reputation: 448
1.<input id="kw1"></input>
2.<input></input>
The first one, I can use document.getElementById
to get the object, but on some websites, like the second, there is no id in element, but I also want to get the object. How can I do this ? And do not use JQuery
Upvotes: 3
Views: 15373
Reputation: 7290
You can use:
document.getElementsByTagName("input");
which will return a list of objects of type "input"
Upvotes: 1
Reputation: 1686
You can use document.getElementsByTagName('input'), but this give you all input elements.
But since you have nothing else to identify that element, you can not be more specific.
Upvotes: 1
Reputation: 2821
you can do this by using :
getElementsByTagName
example :
var elements = document.getElementsByTagName('input'); // returns array
for more broader details in using it click here
Upvotes: 9
Reputation: 68790
Use document.getElementsByTagName('input')
instead.
It'll return you an array with every input
.
Upvotes: 2