1

My pop up after 5 seconds will appear. I want to Disable or Hidden Button X on Pop Up. I tried with Script: But it did not work. Can you help me ! Thanks you

<script type="text/javascript">
document.getElementsByClassName('cf-cta-close').style.display = 'none';
 </script>

enter image description here

August
  • 11
  • 1
  • Does this answer your question? [What do querySelectorAll and getElementsBy\* methods return?](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-and-getelementsby-methods-return) –  Feb 11 '20 at 16:29
  • Check the Return value part [here](https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName#Syntax). –  Feb 11 '20 at 16:30
  • You need to wait loaded DOM at least. https://flaviocopes.com/dom-ready/ or https://learn.jquery.com/using-jquery-core/document-ready/ if it works for you. Or try to extend pop-up JS code and add your code. – Kirby Feb 11 '20 at 16:32
  • 1
    document.getElementsByClassName is going to give you a (pseudo) array of items, so its not directly compatible with setting the style as a one-liner - you should only do that if you select a _single item_ such as with getElementByID() . – MikeB Feb 11 '20 at 16:37

1 Answers1

0

Using document.getElementsByClassName("some-class") will match all HTML elements with a class attribute of "some class" in a HTML Collection array.

You can access the style attribute of the first element of the array like this document.getElementsByClassName("some-class")[0].style.display = "none".

A better way of doing this would be to give the HTML element an Id attribute instead of a class and then access it directly using document.getElementById("some-id").style.display = "none"

Farhad Khan
  • 104
  • 2
  • 14