How to apply a work explain for all document?

Discussion in 'Javascript' started by Cylix, Aug 14, 2006.

  1. Cylix

    Cylix Guest

    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?
    Any better way?

    Thank you.
     
    Cylix, Aug 14, 2006
    #1
    1. Advertising

  2. Cylix

    BinnyVA Guest

    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;

    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>
     
    BinnyVA, Aug 14, 2006
    #2
    1. Advertising

  3. Cylix

    Cylix Guest

    Thanks for reply,

    I mead that I have a number of HTM pages, maybe news acticle,
    All of them contains the word "APPA".
    I want to have a js. which atttached to all HTM,
    so that the js will found out all the term "APPA" and set onMouseOver
    event to the term "APPA"
     
    Cylix, Aug 17, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    995
    Marrow
    Jul 18, 2003
  2. Hari Prakash
    Replies:
    1
    Views:
    374
    Martin Honnen
    Jul 16, 2004
  3. vunet
    Replies:
    6
    Views:
    380
    Neredbojias
    Jan 15, 2008
  4. chirs

    document.tagID vs document.all.tagID

    chirs, Dec 1, 2003, in forum: Javascript
    Replies:
    1
    Views:
    83
    Lasse Reichstein Nielsen
    Dec 1, 2003
  5. Jim Ley
    Replies:
    3
    Views:
    231
Loading...

Share This Page