|
-
Apr 22nd, 2004, 09:18 AM
#1
Thread Starter
New Member
RESOLVED - (d)html & javascript: using "this" and elements...
I have this javascript code:
Code:
<script type="text/javascript">
function disp()
{
n = document.getElementById('btwo');
n.style.display=n.style.display=='block'?'none':'block';
}
</script>
And this html:
Code:
<tr id="two">
<td><a href="javascript:void(0)" class="clink" onclick="disp()">Topic: Two</a>
<blockquote id="btwo" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
The bit in the blockquote is initially hidden, then when you click the link ("Topic: Two"), it shows the hidden bit (..toggles display style).
I need to un-hardcode the 'btwo' in the script part...
I tried using onclick="disp(this)" , but my knowledge of the DOM tree is pitiful...
Any help / hints appreciated.
Thanks
Last edited by deeperdish; Apr 22nd, 2004 at 09:42 AM.
-
Apr 22nd, 2004, 09:24 AM
#2
Frenzied Member
Code:
<script type="text/javascript">
function disp()
{
n = document.getElementById('btwo');
n.style.display = (n.style.display=='block')?'none':'block';
return false;
}
</script>
<tr id="two">
<td><a href="#" class="clink" onclick="return disp()">Topic: Two</a>
<blockquote id="btwo" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
-
Apr 22nd, 2004, 09:26 AM
#3
Frenzied Member
there could be a nextElement() type function which would work better, but I don't know of any such thing. so here's a party un-hardcoded change:
Code:
<script type="text/javascript">
function disp(_obj)
{
n = document.getElementById(_obj);
n.style.display = (n.style.display=='block')?'none':'block';
}
</script>
<tr id="two">
<td><a href="#" class="clink" onclick="disp('btwo')">Topic: Two</a>
<blockquote id="btwo" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
Have I helped you? Please Rate my posts. 
-
Apr 22nd, 2004, 09:33 AM
#4
Thread Starter
New Member
Yep, I suppose that code is neater, but it doesn't answer my question...
The toggling of the blockquote display is not the problem, that works fine.
The thing is: I have more rows in my table with similar code to the bit in my original post. I dont want to have the script part for each row in the table... Hope that clears thing up a bit more...
Here's more code to illustrate my point further:
Code:
<tr id="one">
<td><a href="javascript:void(0)" class="clink" onclick="disp()">Topic: One</a>
<blockquote id="bone" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
<tr id="two">
<td><a href="javascript:void(0)" class="courselink" onclick="disp()">Two</a>
<blockquote id="btwo" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
<tr id="three">
<td><a href="javascript:void(0)" class="clink" onclick="disp()">Topic: Three</a>
<blockquote id="bthree" class="DisplayNone">Some bumf about this topic</blockquote>
</td>
</tr>
I want to use the same script code to handle the toggling of the blockquote display....
-
Apr 22nd, 2004, 09:40 AM
#5
Thread Starter
New Member
RESOLVED - (d)html & javascript: using "this" and elements...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|