1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function ajouter(){
var mondoc = document.createElement("div");
var monlien = document.getElementById("Lien");
var montexte = mondoc.createTextNode('<xml id="nomIdentifiant" src="test.xml" />');
var ensemble = document.getElementById("ensemble");
//create function, it expects 2 values.
function insertAfter(mondoc,ensemble) {
//target is what you want it to go after. Look for this elements parent.
var parent = ensemble.parentNode;
//if the parents lastchild is the targetElement...
if(parent.lastchild == ensemble) {
//add the newElement after the target element.
parent.appendChild(mondoc);
} else {
// else the target has siblings, insert the new element between the target and it's next sibling.
parent.insertBefore(mondoc, ensemble.nextSibling);
}
}
}
</script>
</head>
<body>
<div id="ensemble">
<a href="#" id="Lien" onclick="ajouter()">Ajouter</a>
</div>
</body>
</html> |
Partager