Hi Cylix,
In my site,
There will be some word shold have explaination.
The explaination will be shown in a layer(<div>).
How can I add only a JS file to set all the word in every document?
Is it using regular expression and replace the body.innerHTML with the
word to onclick event?
I did not completely understand what you asked, but try this...
<html><head>
<title>Explanations</title>
<style type="text/css">
#explainations dd {
display:none;
}
</style>
<script type="text/javascript">
function init() {
var explainations = document.getElementById('explainations');
var terms = explainations.getElementsByTagName("dt");
for(var i=terms.length-1;i>=0;i--) {
var ele = terms[i];
ele.onclick=function(e) {
if(!e) var e = window.event;
var explaination = this.nextSibling;
if(explaination.style.display != "block")
explaination.style.display="block";
else explaination.style.display = "none";
}
}
}
window.onload=init;
</script>
</head>
<body>
<dl id="explainations">
<dt>Hello</dt><dd>A form of greeting</dd>
<dt>42</dt><dd>The answer to life, the universe and everything</dd>
</dl>
</body></html>