WEB DEV JS AND PHP
Hi. I am starting to program dots and boxes. The rest of my website is written in php html and css. However, for this part I will need css. How do I write the js? Where do I put it?
@rsmith6559
You have a file with css. It is the same with javascript. You just have to add it at the end of the file instead of the header
Here's a skeleton for you, where css can be placed inside the head, and javascript at the bottom of the body. `<!doctype html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>title</title> <style type="text/css"> #box { background-color: blue; width: 100px; height: 100px; } </style> </head> <body> <div id="box"></div> <script type="text/javascript"> document.getElementById("box").onclick = function() { alert("you clicked"); } </script> </body> </html>` You can even keep the files separate, and just reference to them like so; `<!doctype html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>title</title> <link rel="stylesheet" type="text/css" href="url.css" /> </head> <body> <div id="box"></div> <script type="text/javascript" src="url.js"></script> </body> </html>`
Join our real-time social learning platform and learn together with your friends!