Vị trí đặt thẻ <script>
- Trong thẻ <head>
- Trong thẻ <body>
- File ngoài (.js)
Script phía client luôn đặt trong thẻ <script>.
Ví dụ minh họa
<html> <body> <p>Ví dụ ghi "JavaScript is not java" vào phần tử id="script"</p> <p id="imp"></p> <script> document.getElementById("imp").innerHTML = "JavaScript is not java"; </script> </body> </html>
Kết quả
Ví dụ ghi "JavaScript is not java" vào phần tử id="script" JavaScript is not java
Giải thích
Mọi code JS phải trong <script>. Ví dụ dùng getElementById gán nội dung qua thuộc tính id.