Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: 2 classes for the same text

  1. #1
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 2 classes for the same text

    How can I add two classes to the same link? (One of the classes is set up with javascript, the other is just a normal CSS style)

  2. #2
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Code:
    class="classone classtwo"

  3. #3
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i tried that, but for some reason it doesn't seem to work.

  4. #4
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    then you must be testing on some very outdated browser, like IE5.0

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Could you provide a demo?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm not really sure of the question in hand, either.
    - Mike

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    HTML Code:
    <a href="some.htm" class="classone classtwo">Link Text</a>
    is the proper way to do this in an HTML tag. If you are setting things via javascript, it would depend upon just what you wanted to do. If you want to take the existing className and add to it:

    Code:
    el.className=el.className+' classtwo';
    where the variable 'el' represents the element that you want to do this to. Removing the second class could be done like so:

    Code:
    el.className=el.className.replace(/ classtwo/, '');
    There are so many ways to do things in javascript though, the above are just examples - ideas. Exactly how you go about this should be tailored to all possible situations that could arise on your page(s) that use the code.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So, here is the code that I'm trying to use. the two classes work fine seperatly, just not together.
    Code:
    <head>
    <style type="text/css"> 
    .xlink {cursor:url("pound.cur")} 
    
    
    
    </style> 
    
    
    <script type="text/javascript">
    var bulletimg='<img id="bullet" style="position:absolute; left: -300px" src="bah.gif">'
    
    var bulletoffX=2 //Set horizontal offset of bullet image from link's root. (ie: -2 or 5)
    var bulletoffY=8 //Set vertical offset of bullet image from link's root. (ie: -2 or 5)
    
    function caloffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
    }
    return totaloffset;
    }
    
    function displaybullet(linkobj){
    bulletobj.style.left=caloffset(linkobj, "left")-bulletobj.width-bulletoffX+"px"
    bulletobj.style.top=caloffset(linkobj, "top")-bulletoffY+linkobj.offsetHeight/3+"px"
    bulletobj.style.visibility="visible"
    }
    
    function modifylinks(){
    bulletobj=document.all? document.all.bullet : document.getElementById("bullet")
    for (i=0; i<document.links.length; i++){
    if (document.links[i].className=="ddbullet"){
    document.links[i].onmouseover=function(){displaybullet(this)}
    document.links[i].onmouseout=function(){bulletobj.style.visibility="hidden"}
    }
    }
    }
    
    if (document.all || document.getElementById)
    document.write(bulletimg)
    
    if (window.addEventListener)
    window.addEventListener("load", modifylinks, false)
    else if (window.attachEvent)
    window.attachEvent("onload", modifylinks)
    else if (document.getElementById || document.all)
    window.onload=modifylinks
    
    </script>
    </head>
    <body>
    <a href="scops.html" class="ddbullet xlink" STYLE="text-decoration: none" target="B">S.C.O.P.s</a>
    </body>
    Thanks for the help so far.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Change this line:
    Code:
    if (document.links[i].className=="ddbullet"){
    to:
    Code:
    if (document.links[i].className.indexOf("ddbullet") !== -1){
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That change in code fixed it. Thanks!

Bookmarks

Posting Permissions

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