0

I have java script widged which also serves advertisement logo and link. I'm trying to remove the link. Tried the following script code:

<script>
const element = document.querySelector('#apps-google-reviews-1db34d2f-5a02-5eb0-a222-cec57773ac19 > div > a');
element.remove();
</script>

This is working in the browser's console but when I add it as a script in the HTML there is the following error in the console:

Uncaught TypeError: Cannot read properties of null (reading 'remove')

Basicaly the selector didn't catch the element.

evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
SScast
  • 59
  • 1
  • 10
  • _"Basicaly the selector didn't catch the element."_ - exactly. You need to do some debugging and figure out why. If you edit the question to include a [mcve] we might be able to help – evolutionxbox Jul 20 '22 at 14:02
  • Does this answer your question? [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/q/14028959/328193) To be honest, we don't even know if *the selector* is correct, let alone if the script is executing when the element actually exists. All we can say for certain is that the element you're looking for doesn't exist in the document when you look for it. – David Jul 20 '22 at 14:06

0 Answers0