UHU-StartseiteInformatikKurseW-Seminar App-ProgrammierungHTML5
javascript und HTML-Elemente


document.getElementById
<!DOCTYPE html> <!-- Start für HTML5 --> <html lang="de"> <head> <script> function aendereText(){ var e = document.getElementById("Element1") e.innerHTML = "duzieduzie"; } </script> </head> <body> <div id="Element1"> Text in Element 1 </div> <span onclick="aendereText()" style="background-color: yellow" >neuer Text</span> </body> </html>



  • Die Funktion "aendereText()" sucht sich das HTML-Element mit der id "Element1" und ändert dessen Text mit Hilfe der Eigenschaft "innerHTML".
  • Die Funktion wird erst aufgerufen, wenn "neuer Text" angecklickt wird.



Zugriff auf css-styles mit Javascript
Beispiel: e.style.backgroundColor = "red" Kompletter Quelltext:
<!DOCTYPE html> <!-- Start für HTML5 --> <html lang="de"> <head> <script> function aendereText(){ var e = document.getElementById("Element1") e.style.backgroundColor = "red" } </script> </head> <body> <div id="Element1"> Text in Element 1 </div> <span onclick="aendereText()" style="background-color: yellow" >neuer Text</span> </body> </html>



Javascript Style-Attribute
background	background
background-attachment	backgroundAttachment
background-color	backgroundColor
background-image	backgroundImage
background-position	backgroundPosition
background-repeat	backgroundRepeat
border	border
border-bottom	borderBottom
border-bottom-color	borderBottomColor
border-bottom-style	borderBottomStyle
border-bottom-width	borderBottomWidth
border-color	borderColor
border-left	borderLeft
border-left-color	borderLeftColor
border-left-style	borderLeftStyle
border-left-width	borderLeftWidth
border-right	borderRight
border-right-color	borderRightColor
border-right-style	borderRightStyle
border-right-width	borderRightWidth
border-style	borderStyle
border-top	borderTop
border-top-color	borderTopColor
border-top-style	borderTopStyle
border-top-width	borderTopWidth
border-width	borderWidth
clear	clear
clip	clip
color	color
cursor	cursor
display	display
filter	filter
font	font
font-family	fontFamily
font-size	fontSize
font-variant	fontVariant
font-weight	fontWeight
height	height
left	left
letter-spacing	letterSpacing
line-height	lineHeight
list-style	listStyle
list-style-image	listStyleImage
list-style-position	listStylePosition
list-style-type	listStyleType
margin	margin
margin-bottom	marginBottom
margin-left	marginLeft
margin-right	marginRight
margin-top	marginTop
overflow	overflow
padding	padding
padding-bottom	paddingBottom
padding-left	paddingLeft
padding-right	paddingRight
padding-top	paddingTop
page-break-after	pageBreakAfter
page-break-before	pageBreakBefore
position	position
float	styleFloat
text-align	textAlign
text-decoration	textDecoration
text-decoration: blink	textDecorationBlink
text-decoration: line-through	textDecorationLineThrough
text-decoration: none	textDecorationNone
text-decoration: overline	textDecorationOverline
text-decoration: underline	textDecorationUnderline
text-indent	textIndent
text-transform	textTransform
top	top
vertical-align	verticalAlign
visibility	visibility
width	width
z-index	zIndex


optimal sichtbar mit Firefox Formeln mit asciimath Druckversion