Jump to content

Showing Sub Links When The User Clicks A Topic


Flic
 Share

Recommended Posts

Hi,I've used this code before and it worked fine, but its just not working now!Basically I have a list of sub links that should appear when the user clicks on the super link, see nice and simple! But its just not working!Have tried quite a few things to it but no luck!

<script type="text/javascript">        function view(selected){                selected.style.display = "";        }        </SCRIPT>...<a class="video" href="java script:view(aftertime);">After Time</a><ul id="aftertime"><li><a class="video" href="events.html" onclick="java script:window.open()">Song 1</a></li><li><a class="video" href="">Sub link 2</a></li></ul>

Any help would be very much appreciated! Thanks!

Link to comment
Share on other sites

script type="text/javascript"> function view(selected){ selected.style.display = ""; } </SCRIPT>...<a class="video" href="java script:view(aftertime);">After Time</a><ul id="aftertime"><li><a class="video" href="events.html" onclick="java script:window.open()">Song 1</a></li><li><a class="video" href="">Sub link 2</a></li></ul>
In the function call, 'aftertime' should be single quoted. Then in the function, selected should be wrapped in document.getElementById(selected). Also, never ever ever need to use onclick="java script:doSomething" -as javascript is already assumed by the browser in a onwhatever="dosomething". It should not be used in the href attribute either. Then, use return false in the onclicks to prevent the browser from following it's default action. So the following would be more correct:
<script type="text/javascript">		function view(selected){				document.getElementById(selected).style.display = "";		}</SCRIPT>...<a class="video" href="#" onclick="view('aftertime'); return false;">After Time</a><ul id="aftertime"><li><a class="video" href="events.html" onclick="window.open(this.href); return false;">Song 1</a></li><li><a class="video" href="">Sub link 2</a></li></ul>

Link to comment
Share on other sites

Also, never ever ever need to use onclick="java script:doSomething" -as javascript is already assumed by the browser in a onwhatever="dosomething".
Notice how it wasn't onclick="java script:doSomething" but href="java script:doSomething" :)Your likely problem is that you did href="java script:doSomething" with a space, with a space java script:doSomething won't work in Firefox, Chrome, and possibly other browsers that I don't care to test.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...