1

I have a button that I want to hide in an HTML page, I cannot figure out how to access an element with no ID nor name.

HTML code:

<INPUT onclick=getAddress2(event,1) class=Design_btn02 style="IME-MODE: active" type=button value="Address">

How can I access the button above?

5
  • 3
    document.getElementsByTagName('input')[0], document.querySelector('input.Design_btn02') Commented Mar 16, 2017 at 1:49
  • Or document.getElementsByClassName('Design_btn02')[0] Commented Mar 16, 2017 at 1:49
  • The querySelector will only return the first occurrence of input.Design_btn02. How can I get all the doms that matching input.Design_btn02? Commented Mar 16, 2017 at 1:52
  • 1
    @ramwin - querySelectorAll(). Commented Mar 16, 2017 at 2:20
  • Thank you. I think this is more convenient then document.getElementById. Commented Mar 16, 2017 at 5:16

3 Answers 3

3

As the element has a class, try the following:

document.getElementsByClassName('Design_btn02')[0].style.visibility= 'hidden';
<INPUT onclick=getAddress2(event,1) class=Design_btn02 style="IME-MODE: active" type=button value="Address">

Sign up to request clarification or add additional context in comments.

Comments

2

Use command document.getElementsByClassName('Design_btn02'). It will return a list containing all the doms whose calss is Design_btn02.

Comments

1

The element has a class name.So we can access it with the help of class name.document.getElementsByClassName('Design_btn02')

The statement document.getElementsByClassName('Design_btn02') returns an array of all the elements having class name 'Design_btn02'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.