Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorxapss
    • CommentTimeJan 15th 2007
     permalink
    For instance:
    I have a li and want to make it clickable. I have the following, is this correct? I can't be because it doesn't work. I don't see why..
    <li onclick="window.open(this.getElementsByTagName('a').href)"><a href="testpage.html">Go to testpage</a></li>
    I can't get it working with getElementByTagName, only by Id.

    Thanks in advance!
    • CommentAuthorvarland
    • CommentTimeJan 15th 2007
     permalink

    Why would you be doing this? If your link is the only thing in the list item, why do you need a click handler on the list item itself?

    To actually answer your question, I believe the getElementsByTagName function returns an array, even if it only finds one element. Therefore, you would need to do something like:

    <li onclick="window.open((this.getElementsByTagName('a'))[0].href);"><a href="testpage.html">Go to testpage</a></li>

    Even if that works, you'd be better off attaching the handler to the link itself. If you return false from the link's "onclick" handler, the link won't actually work.

    I still don't think you should be doing this. It's also considered somewhat bad practice to use inline javascript like that. Take a look at Ben Nolan's Behaviour library.

    • CommentAuthorxapss
    • CommentTimeJan 15th 2007
     permalink
    Thank you for ben nolan's library, this is exactly what i wanted to do in the end! I just wanted it to test it inline, and than make it more abstract if it worked..
    • CommentAuthornavdeep
    • CommentTimeJan 17th 2007
     permalink
    gf
Add your comments
    Username Password
  • Format comments as (Help)