03.
<head>
04.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
05.
<title>Untitled Document</title>
06.
<style type=
"text/css"
>
07.
#red {
08.
width: 300px;
09.
height :300px;
10.
background:#F00;
11.
}
12.
#blue {
13.
width: 300px;
14.
height :300px;
15.
background:#00F;
16.
}
17.
</style>
18.
19.
</head>
20.
21.
<body>
22.
<div id=
"demo"
></div>
23.
<a href=
"#"
onclick=
"red()"
>คลิก</a>
24.
<script>
25.
26.
function
red(){
27.
document.getElementById(
"demo"
).innerHTML =
"<div id=\"red\"></div>"
;
28.
var
ola = document.getElementsByTagName(
"a"
)[0];
29.
ola.setAttribute(
"onclick"
,
"blue()"
);
30.
}
31.
32.
function
blue(){
33.
document.getElementById(
"demo"
).innerHTML =
"<div id=\"blue\"></div>"
;
34.
var
ola = document.getElementsByTagName(
"a"
)[0];
35.
ola.setAttribute(
"onclick"
,
"red()"
);
36.
}
37.
</script>
38.
</body>
39.
</html>