Bureaucrats, emailconfirmed
1,221
edits
Line 59: | Line 59: | ||
Im Javascript-Code kann auf Elemente im HTML zugegriffen werden: | Im Javascript-Code kann auf Elemente im HTML zugegriffen werden: | ||
<source lang="HTML4Strict | <source lang="HTML4Strict"> | ||
<!-- in der HTML Datei--> | <!-- in der HTML Datei--> | ||
<p id="changeMe">Lorem Ipsum</p> | <p id="changeMe">Lorem Ipsum</p> | ||
</source> | </source> | ||
<source lang="JavaScript | <source lang="JavaScript" > | ||
//im Javascript | //im Javascript | ||
var domElement = document.getElementById("changeMe"); | var domElement = document.getElementById("changeMe"); | ||
domElement.style.color = red; | domElement.style.color = red; | ||
</source> | </source> | ||
document.getElementById() holt das Element mit der übergebenen Id (hier:"changeMe"). In dem Beispiel ist das das | document.getElementById() holt das Element mit der übergebenen Id (hier:"changeMe"). In dem Beispiel ist das das <p>. In der folgenden Zeile wird dann die Schriftfarbe geändert. | ||
Eine ähnliche Funktion ist document.getElementsByTagName(), diese gibt kein Element direkt zurück sondern ein Array mit allen Elementen die dieses Tag haben. | Eine ähnliche Funktion ist document.getElementsByTagName(), diese gibt kein Element direkt zurück sondern ein Array mit allen Elementen die dieses Tag haben. | ||
== Event-Handler == | == Event-Handler == |