atrybut HTML DOM className
Definicja i Wykorzystanie
zestawy własności className lub zwraca atrybut class elementu.
gramatyka
Get wartości właściwości:
HTMLElementObject.className
Ustawienie wartości właściwości:
HTMLElementObject.className= classname
Pomoc Browser
Wszystkie główne przeglądarki obsługują atrybut className
Przykłady
Przykłady
Zwraca atrybut klasa elementu 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>
wyjście:
Body CSS class: mystyle
An alternate way: mystyle
An alternate way: mystyle
Spróbuj »