How do I get Nice Titles to apply to only the superscript tag?
October 6, 2005 11:44 AM   Subscribe

Javascript newbie: I'm using Nice Titles for footnotes on a webpage. How can I get Nice Titles to apply only to links within the superscript tag and not to all links on the page?

I'm sure the solution is simple, but I've barely begun learning Javascript, and I'm stumped.
posted by lychee to Computers & Internet (3 answers total)
 
I assume you mean you'd want to apply to this:

<superscript>
<a href >something</a>
</superscript>

but not
<a href >somethingelse</a>

If so, what you're concerned with is this line:

document.getElementsByTagName("a");

That's operating on the whole document. You don't want that, you want to find a tags within superscripts. I -think- this is how that would be done.
    if( !document.links ) {
      document.links = document.getElementsByTagName("superscript");
      for (var ti=0;ti<document.subscripts.length;ti++) {
          var lnk = document.subscripts[ti];
          document.links = lnk.getElementsByTagName("a");
      }
      for (var ti=0;ti<document.links.length;ti++) {
          var lnk = document.links[ti];
          if (lnk.title) {
              lnk.setAttribute("nicetitle",lnk.title);
              lnk.removeAttribute("title");
              addEvent(lnk,"mouseover",showNiceTitle);
              addEvent(lnk,"mouseout",hideNiceTitle);
              addEvent(lnk,"focus",showNiceTitle);
              addEvent(lnk,"blur",hideNiceTitle);
          }
      }    
    }    
I'm not DOM guy but maybe this'll give you a better idea why it's working on some and not others.
posted by phearlez at 1:03 PM on October 6, 2005


Best answer: for (var ti=0;ti<document.links.length;ti++) {
    var lnk = document.links[ti];

    if (lnk.title && lnk.parentNode.tagName.toLowerCase() == "sup") {
        ...
    }
}

posted by Khalad at 1:48 PM on October 6, 2005


Response by poster: Thank you both very much! It works, it works!
posted by lychee at 2:18 PM on October 7, 2005


« Older "Cloaked" domain workaround   |   Help Desk Software Newer »
This thread is closed to new comments.