General Community > Scripting Help

Simple JS, can't make it work for more than first post (cause I'm a moron ha ha)

(1/6) > >>

Jade Elizabeth:
So I am using JS from this tutorial to show and hide things....But I seem to have overlooked the whole "I need it to work for each message" thing. I'm not really familiar with I was hoping someone could help me get it to work per post?

Live link.

If you click any of the blue arrows on the live link above it interacts with the first post only. It should show an up arrow when clicked on any post, but only in the post it is clicked on. I have no idea what I'm doing :-[.

You need to work with every message ID, I have this simple script that does the job:

--- Code: ---<!--
function toggleDiv(divid){
if(document.getElementById(divid).style.display == \'none\'){
document.getElementById(divid).style.display = \'block\';
document.getElementById(divid).style.display = \'none\';

--- End code ---

Then all you need to have is an anchor tag with the message ID you want to change:

<a href="javascript:void(0)" onmousedown="toggleDiv(someIDhere);" >title</a>

can be onmousedown or any other action you want.

Matthew K.:
You need to have an identifier and unique value for each post.

Specifically with their example, you'd want to change it to something like...

--- Code: ---<p>...This is all visible content...
<a href="#" id="example-show" class="showLink"
onclick="showHide('post_' . $message['id']);return false;">See more.</a>
<div id="post_', $message['id'], '" class="more">
<p>...This content is hidden by default...</p>
<p><a href="#" id="example-hide" class="hideLink"
onclick="showHide('example');return false;">Hide this content.</a></p>
--- End code ---

Jade Elizabeth:
Labradoodle how would I change the JS to work?

Suki I can't seem to get it to work, did I do something wrong here?

--- Code: --- // Let's "show" some things!
echo '<a href="javascript:void(0)" onmousedown="toggleDiv(quickbuttonshow' , $message['id'] , ');"><img src="', $settings['images_url'], '/BRSquickbuttons/up.png" alt="Show/Hide More Options!" title="Show/Hide More options!" class="paddingbottom" /></a><br />';

--- End code ---

I am so confused. How do I set all these divs to display: none? If they all have message IDs in them that's like a billion classes :-X.

Thanks for helping me guys, I appreciate it!

Matthew K.:
You wouldn't have to change the JS at all.


[0] Message Index

[#] Next page

Go to full version