views:

89

answers:

3

Im working with the following code;

<a href=\"#\" onClick=\"if($(this).next('div').css('display') == 'none') { $(this).next('div').show('fast'); } else { $(this).next('div').hide('fast'); } return false;\">Link</a>

What i need to do, is change the part if($(this).next('div'), to target a specific element ID, not the next one from current location.

Any ideas are much appreciated, as well as explinations.

Thanks in advance.

+2  A: 

So what you want to do is convert:

 <a href=\"#\" onClick=\"if($(this).next('div').css('display') == 'none') { $(this).next('div').show('fast'); } else { $(this).next('div').hide('fast'); } return false;\">Link</a>

into:

<a href=\"#\" onClick=\"if($('#SomeElement').css('display') == 'none') { $('#SomeElement').show('fast'); } else { $('#SomeElement').hide('fast'); } return false;\">Link</a>

????

But of course, I'm assuming that there is only one SomeElement on the page. I'm trying to make sure I understand the question...

drachenstern
+3  A: 

Target the ID of the element you want to change. E.g.

<a href="#" onClick="if('#myElement').css('display') == 'none') { $('#myElement').show('fast'); } else { $('#myElement').hide('fast'); } return false;">Link</a>

HTML:

<div id="myElement">Whatever</div>
Gert G
+5  A: 

You can use $('#myDiv') to select an element with id="myDiv". Also, you should be using the toggle function for this:

<a href=\"#\" onClick=\"$('#myDiv').toggle('fast');\">Link</a>
colinmarc