简体   繁体   中英

JavaScript function not working with onclick

Here is the problem(if you can call it so), every time i write JS that includes functions it doesn't work. I know it's related to spaces, line-breaks or sth like that. Maybe I don't know the rule or the syntax. i'm using sublime text3(if it's related). And i will be thankful if you explain the reason to me so i won't be facing this problem ever again. here is a code that doesn't work on my computer

 <script type="text/javascript"> document.getElementById("circle").onclick = function() { document.getElementById("circle").style.display = "none"; } </script> 

Are you sure that the element with the ID "circle" has the onclick function as one of its properties? you can check the property list with the dir function that is on the console.

console.dir(document.getElementById("circle"));

The dir is not for production though. It does come in handy in development and debugging.

MDN Console.dir()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM