PDA

View Full Version : A href needs two javascript statements



sniperman
08-16-2009, 08:29 AM
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.


<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

sniperman
08-16-2009, 08:38 AM
Sorry, quickly figured it out, for anyone who wishes to know.

The code would be...


<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.