DOM-Elemente finden
var list = document.getElementsByTagName("UL")[0];
var elem = document.getElementById("xyz");
Einbindung in HTML
<button onclick="myFunction()">Click me</button>
<p onclick="myFunction()">Click me to change my text color.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red";
}
<button onclick="myFunction()">Copy Text</button>
<script>
function myFunction() {
document.getElementById("text2").value = document.getElementById("text2").value;
document.getElementById("textarea2").innerHTML = document.getElementById("textarea2").innerHTML;
var field = document.getElementById("field1");
field.style.visibility = field.style.visibility == "hidden" ? "visible" : "hidden";
}
</script>
Typen
String
text += ".";
Numbers
- Nur Gleitpunktzahlen werden benutzt.
- Daher haben Ganzzahlen max. 53 Bit
- x=Math.min(1,2,3); r=Math.floor(x); w=Math.sqrt(x);
Dictionary
var x = { "zahl" : 33, "pair" : { "x" : true } };
Klassen
'use strict';
class Polygon {
constructor(height, width) {
this.name = 'Polygon';
this.height = height;
this.width = width;
}
sayName() {
ChromeSamples.log('Hi, I am a ', this.name + '.');
}
sayHistory() {
ChromeSamples.log('"Polygon" is derived from the Greek polus (many) ' +
'and gonia (angle).');
}
static className() {
return "Polygon";
}
}
const p = new Polygon(300, 400);
p.sayName();