Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Class attribute in NS4

    Hello,
    Could you please help me to change dynamically in javascript the class name in <a> tag in NS4 ?
    <a id="opsa" class="c" href"...">...</a>

    Thank you very much

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Gets very messy:
    Code:
    <html> 
    <head> 
    <title>untitled</title> 
    <style type="text/css"> 
    
    .oldclass1 { 
    color: #00ff00; 
    } 
    .oldclass2 { 
    background: #00ffff; 
    } 
    .newclass1 {
    font-style: italic; 
    color: #ff0000; 
    } 
    .newclass2 {
    font-weight: bold; 
    background: #ffff00; 
    } 
    
    </style>
    <script type="text/javascript" language="JavaScript">
    
    var NSlinks = new Object();
    //linktext: the content of the <a> tag without the class name
    //text: the <a>text between</a>
    NSlinks['a1'] = {linktext: 'href="javascript&#58;alert(&#92;'test 1&#92;')"' , text: 'test 1 text'};
    NSlinks['a2'] = {linktext: 'href="javascript&#58;alert(&#92;'test 2&#92;')"' , text: 'test 2 text'};
    
    function changeCSSclass(id, classname) {
    if (!document.layers) document.getElementById(id).className = classname;
    else {
    var HTML = '<a class="' + classname + '" ' + NSlinks[id].linktext + '>';
    HTML += NSlinks[id].text + '</a>';
    var l = document['NS' + id];
    l.document.write(HTML);
    l.document.close();
    }
    }
    
    </script>
    </style> 
    </head> 
    <body>
    <layer id="NSa1"> 
    <a id="a1" class="oldclass1" href="javascript&#58;alert('test 1')">test 1 text</a>
    </layer><br><br>
    <layer id="NSa2"> 
    <a id="a2" class="oldclass2" href="javascript&#58;alert('test 2')">test 2 text</a>
    </layer><br><br><br> 
    <a href="#" 
    onmouseover="changeCSSclass('a1','newclass1')" 
    onmouseout="changeCSSclass('a1','oldclass1')">change test 1 class</a><br>
    <a href="#" 
    onmouseover="changeCSSclass('a2','newclass2')" 
    onmouseout="changeCSSclass('a2','oldclass2')">change test 2 class</a> 
    </body> 
    </html>
    Last edited by adios; 07-09-2002 at 11:57 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •