I get an empty array when I put the following:
document.getElementsByTagName("input");
However if I select an element with the inspect option and then put document.getElementsByTagName("input");
it back this time it no longer returns an empty array, this time it does contain all the inputs that are part of the page.
How can I use document.getElementsByTagName("input");
it and make it work without using the inspect option?
This does not happen to me on all pages, only on some.
The DOM allows you to nest elements, that is, you have a document object, which includes other document objects, as is the case with a page that includes an iframe.
In the Chrome console, right next to the delete console button, is the "scope" selector. There you can select the element that includes the document of your interest. The details are in Choosing the execution context , of which the following image should be highlighted, where the previously mentioned selector is highlighted.
Related
Normally the chrome console allows you to do these functions as long as all the attributes of the page are saved in the cache, if your page does not save correctly or completely in your page this chrome function will not be activated until inspections and the data is save in cache (for this it works for you on some pages and not on others)
The simplest option that I think can serve, try this
Create function in javascript
This will allow you to consult what you need, just by calling the tagname function (or whatever you call it) from the chrome console (or another browser)
I leave you information about getElementsByTagName
Cheers
https://www.w3schools.com/jsref/met_document_getelementsbytagname.asp
Sorry, the intention is that you learn, you want to locate an element in the form, if so you are going the wrong way, you should use document.getElementById() and put id to the tags, of course if I do not answer your question, a thousand pardons , layers what you want is to invent a new jquery.
As for the Chrome console, notice that typing document(dot) auto-completes and lists the functions. in particular, the method by which you ask if there are several "inputs" will return a list, so you will have to go through it and find the appropriate one. Can you do
and then:
arr is a variable allocated in the browser. which by the way you can use as long as you don't reload the page.