<!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"
lang=
"zh-TW"
xml:lang=
"zh-TW"
>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>Image</title>
<script type=
"text/javascript"
>
function
before() {
var
image = document.getElementById(
'myimg'
);
var
alink = document.createElement(
'a'
);
alink.appendChild(document.createTextNode(
'Google'
));
alink.href =
"http://www.google.com/"
;
image.parentNode.insertBefore(alink, image);
}
function
wrap() {
var
image = document.getElementById(
'myimg'
);
var
alink = document.createElement(
'a'
);
alink.href =
"http://www.google.com/"
;
alink.appendChild(image.cloneNode(
true
));
image.parentNode.replaceChild(alink, image);
}
function
after() {
var
image = document.getElementById(
'myimg'
);
var
alink = document.createElement(
'a'
);
alink.appendChild(document.createTextNode(
'Google'
));
alink.href =
"http://www.google.com/"
;
if
(image.parentNode.lastChild == image) {
image.parentNode.appendChild(alink);
}
else
{
image.parentNode.insertBefore(alink, image.nextSibling);
}
}
</script>
</head>
<body>
<button onClick=
"before()"
>Before</button>
<button onClick=
"wrap()"
>Warp</button>
<button onClick=
"after()"
>After</button>
<img id=
"myimg"
src=
"example.jpg"
/>
</body>
</html>