Results 1 to 2 of 2

Thread: A href needs two javascript statements

  1. #1
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default A href needs two javascript statements

    Just a quick one.

    I have an anchored list and need two events to happen when someone clicks on the link. Both of them involve href.

    The first is for href="#1" to focus the user to the specified page area.
    The second is to invoke a javascript function.

    Code:
    	<ul>
    		<li><a href="#1""javascript:highlightCode('1')">TEXT TEXT</a></li>
    	</ul>
    
    <div id="1">
    </div>
    I know anchors allow multiple javascript statements but i don't know how to use javascript to focus on a specific area in the document before the script is executed.

    Thanks in advance

  2. #2
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    Sorry, quickly figured it out, for anyone who wishes to know.

    The code would be...

    Code:
    <li><a href="javascript:window.location.href='#1';highlightCode('1')">TEXT TEXT</a></li>
    Furthermore, I placed the first statement inside the highlightCode() script and it worked fine.

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
  •