atribut HTML DOM className
Definisi dan Penggunaan
className set properti atau mengembalikan atribut kelas elemen.
tatabahasa
Dapatkan nilai properti:
HTMLElementObject.className
Pengaturan nilai properti:
HTMLElementObject.className= classname
Dukungan Browser
Semua browser utama mendukung atribut className
contoh
contoh
Mengembalikan atribut kelas elemen body:
<html>
<body id="myid" class="mystyle">
<script>
var x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br>");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>
<body id="myid" class="mystyle">
<script>
var x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br>");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>
Output:
Body CSS class: mystyle
An alternate way: mystyle
An alternate way: mystyle
Coba »