I'm trying to search the document using:
document.querySelectorAll("a[href*=google.com]")[0].href;
To search the document for a href containing the google.com URL The strange thing is that it has always worked for me to this day What will have happened? This is the error that shows me:
Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': 'a[href=google.com]' is not a valid selector.
at <anonymous>:1:10
I repeat, I have been using that code for years and today it has stopped working, any solution please?
this is my HTML:
<html>
<head>
<title> MY WEB </title>
</head>
<body>
<a rel="nofollow" href="//www.google.com/" target="_blank">GOOGLE</a>
</body>
</html>
Add quote '' to google.com value
let result = document.querySelectorAll("a[href*='google.com']")[0].href;
let result = document.querySelectorAll("a[href*='google.com']")[0].href;
console.log(result)
<html>
<head>
<title> MY WEB </title>
</head>
<body>
<a rel="nofollow" href="//www.google.com/" target="_blank">GOOGLE</a>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With