-5

i am trying to add hcaptcha to my website but i am doing it in a strange way i want to get if the div with the class 'check' is hidden or not but i cannot do it. here is my code

    var x = document.getElementsByClassName("check")[0]
    var y = window.getComputedStyle(x).display
    alert(y)

it gives me the error 'cip.html:62 Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. at cip.html:62'

  • 2
    You must not have an element with class="check" in your html. – James Dec 20 '21 at 19:26
  • When do you run that code? – j08691 Dec 20 '21 at 19:28
  • Is your ` – Sebastian Simon Dec 20 '21 at 19:44

1 Answers1

0

You need to verify that x is not undefined in case none of the elements have the class your looking for

var x = document.getElementsByClassName("check")[0]
if (x) {
  var y = window.getComputedStyle(x).display
  alert(y)
} else {
  alert('not found')
}
Vincent Menzel
  • 1,040
  • 1
  • 6
  • 17