-2

I want to search the DOM for a form with property name = "formName".

i've tryed with document.querySelectorAll("[name = formName]") but it only works when I inspect the elemnt and then type it on the console.

It looks like I have two IFrames on the page under the so-called "top".

How can I search for the specific element regardless of the selected file? Or at least from "top". enter image description here

Petar Velev
  • 2,305
  • 12
  • 24
  • 3
    `document.querySelectorAll("[name=formName]")` will return a nodeList of all relevant nodes. Please do a basic search before posting, as this is very, very simple. – Reinstate Monica Cellio Jan 24 '18 at 13:21
  • 3
    I'm voting to close this question as off-topic because it shows zero effort and has zero value. – Reinstate Monica Cellio Jan 24 '18 at 13:22
  • I've actually searched it. It was very hard for me to find relevant information due to the inability to type the right thing in google for example. Most of the things I found included JQuery and were presented in the view of creating the application. I needed something simple such as the answer below. Please be more tolerant. If we all were experts we wouldn't need this site. Furthermore, there is no one saying that this is answered elsewhere so why is this bad? Someone might be in the same situation as me and the search will show this question next time. – Petar Velev Jan 24 '18 at 15:29
  • That "answer below" is the first thing I typed in my comment, but less accurate to the question. You need to learn to research *and* pay attention – Reinstate Monica Cellio Jan 24 '18 at 15:31
  • I saw the comment it is even more meaningful than the answer. Thanks a lot and I accept the critic but please be more tolerant. There is no need for negativity in this community. At the end of all it is just about helping other people who know less, right? – Petar Velev Jan 24 '18 at 15:36
  • I searched Google for *javascript find by attribute* and this was the first result... https://stackoverflow.com/questions/2694640/find-an-element-in-dom-based-on-an-attribute-value – Reinstate Monica Cellio Jan 24 '18 at 15:40
  • So is the topic you found also "shows zero effort and has zero value. " – Petar Velev Jan 24 '18 at 15:44
  • Take the criticism and either get used to it or learn from it and get better. I'm helping you. – Reinstate Monica Cellio Jan 24 '18 at 15:45
  • Okay, but it seems like this does not work in my case. I think the problem is in the selected file. This works when I inspect the element and type it on the console but does not when "top" is selected as a file. I'm using chrome – Petar Velev Jan 24 '18 at 15:56

1 Answers1

1

Try this -

document.querySelectorAll('[role="contentinfo"]')

it uses querySelectorAll to select using attribute (role="contentinfo")

Petar Velev
  • 2,305
  • 12
  • 24
deepak thomas
  • 1,118
  • 9
  • 23