<html> <head> <style> .tagging{ border: 1px solid black; width : 20px; height: 30px; } </style> <script> window.onload = function(){ var div = document.getElementsByTagName("div"); div[0].class = "tagging"; } </script> </head> <body> <div></div> </body> </html>
This is my code. I wonder why this does not work when I assign a class attribute through javascript, but it works when I assign inline directly in html
<div class="tagging"></div>
source share