+ 1
Unable to link JS with HTML
Hello, I am trying to link javascript to HTML code using the solo learn app, but there’s an output error of “DataCloneError: The object can not be cloned. at Line: 0”, can someone advise what is wrong and how can I fix it? Below is the code. Regards Ben HTML <!doctype html> <html> <head> </head> <body> <h1 id="Main Title">Soccer Team ratings</h1> <h2 id="winner">Liverpool</h2> <p>This team has an overall rating of 7.01. </p> <h2 id="loser">Lyon</h2> <p>This team has an overall rating of 6.0.</p> <script src="script.js"></script> </body> </html> ——————————————————— JavaScript var heading = document.getElementById("winner"); console.log(heading);
4 Respuestas
+ 2
Ben
You must be using an iOS device? 🤔 You don't have to answer that.
The "DataCloneError" is due to console.log(heading).
To get rid of the error you can convert the object "heading" to a string via heading.toString() or String(heading).
You can also try logging a property of the object "heading" like innerHTML, innerText, or textContent.
https://code.sololearn.com/Wl3EQGTX6914/#js
+ 5
If you're just using Code Playground, there's no need to link the JS within the HTML code. I did not receive DataCloneError after running your original code though.
https://code.sololearn.com/W7Jp2cMkISz7/?ref=app
+ 2
Hi Hatst, thank you for your reply! i was playing around with the code after ive posted the question, if you run it now you should see the DataCloneError. Any idea why is that the case?