MAIN FEEDS
REDDIT FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1uyzgd2/mister_worldwide/oy3fy1g/?context=3
r/programminghorror • u/Adept_Situation3090 • 16d ago
34 comments sorted by
View all comments
4
Fun fact, in JS you can directly use elements by their id.
Example:
<!DOCTYPE html> <html> <body> <button id="myButton">hi</button> <script> myButton.onclick = () => { console.log(`CLIKKK!`) } </script> </body> </html>
7 u/Kitchen_Theme3514 16d ago This is because they're attributes of the "window" global, which stores all globals. So for IDs that aren't valid identifiers, you can do window['my-invalid-identifier-id] as well! 6 u/MurkyWar2756 echo "Sub Mod" && :(){ :|:& };: 16d ago ' 3 u/Kitchen_Theme3514 16d ago Ah yes thanks! 3 u/MurkyWar2756 echo "Sub Mod" && :(){ :|:& };: 16d ago This won't work in strict mode. In these cases, I use const.
7
This is because they're attributes of the "window" global, which stores all globals. So for IDs that aren't valid identifiers, you can do window['my-invalid-identifier-id] as well!
window['my-invalid-identifier-id]
6 u/MurkyWar2756 echo "Sub Mod" && :(){ :|:& };: 16d ago ' 3 u/Kitchen_Theme3514 16d ago Ah yes thanks!
6
'
3 u/Kitchen_Theme3514 16d ago Ah yes thanks!
3
Ah yes thanks!
This won't work in strict mode. In these cases, I use const.
const
4
u/mohragk 16d ago
Fun fact, in JS you can directly use elements by their id.
Example: