Hallo,
Momentan probieren ich eine Classe die vom DIV-Element abgeleitet ist zu erstellen, sowas wie:
function myDiv(){
neueMethode = function(){
machwas;
}
}
myDiv.prototype = document.createElement("DIV");
Das ist, glaube ich, der falsche Ansatz. Du willst das HTMLDivElement http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-22445964 erweitern.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTMLDivElement erweitern</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
<!--
function appendH1(text) {
var h1 = document.createElement("H1");
h1.appendChild(document.createTextNode(text));
this.appendChild(h1);
}
document.createElement("DIV").constructor.prototype.appendH1 = appendH1;
//Wahlweise sollte im Moz. auch das funktionieren:
//document.createElement("DIV").__proto__.appendH1 = appendH1;
//HTMLDivElement.prototype.appendH1 = appendH1;
//http://www.mozilla.org/docs/dom/mozilla/protodoc.html
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
var body = document.getElementsByTagName("BODY")[0]
var d1 = document.createElement("DIV");
var d2 = document.createElement("DIV");
body.appendChild(d1);
body.appendChild(d2);
d1.appendH1("Test d1");
d2.appendH1("Test d2");
//-->
</script>
</body>
</html>
viele Grüße
Axel