Onclick to reveal only one "content" at a time
-
Currently, I have an onclick event that reveals the content of the post (this is displayed as “none” until the onclick event) beneath it after an an image in the post is clicked on.
I only want one post to show up at a time. Say I clicked and revealed the content for Post 1, then if I click on another post (say post 4), I want the content for Post 1 to hide again and the content for Post 4 to show up.
Here is the code for the hidden content
<div><span id="blood-<?php the_ID() ?>" style="display: none;"><?php the_content();?></span> </div>
I used <?php the_ID() ?> to create a unique id for each post, so the click would only reveal the content from the respective post.
I then have this code. First I create an array, using “blood-<?php the_ID() ?>” to refer to the id of each hidden content. [I believe my problem lies here]
I then loop through each value in the array “mysongs” using the for loop, going through each hidden content part and hiding it. Then I use
document.getElementById(showme).style.display = 'block'
to show the desired content (the one that was last clicked on)<script type="text/javascript"> function thesong(showme) { var mysongs = new Array("blood-<?php the_ID() ?>"); for (boom in mysongs) { document.getElementById(mysongs[boom]).style.display = 'none'; } document.getElementById(showme).style.display = 'block'; } </script>
This method worked before when I had a specific id for each hidden content part, but here I use just one id with the <?php the_ID() ?> script, which I think makes a unique id for each post.
However, when creating the array, I basically want to generate a new value for each post using <?php the_ID() ?>, which would refer to the same id for the hidden content. But i guess this isn’t possible or I’m doing it wrong.
Is there anyway you can generate values for an array using just one term, such as mysongs = new array (“x-<?php the_ID() ?>”), which will then generate x-1, x-2, x-3 etc. for each ID.
I know this is probably wrong but if you understand the concept I’m trying to achieve help would be much appreciated, I can’t really find an answer to my specific problem.
Here’s the link to my site
as you can see, clicking on the play button reveals that post’s content, but hiding only works for post 1 and none of the others (most likely because there is only one value in the array that I assumed would automatically generate other values based on ID, but i guess not..)
- The topic ‘Onclick to reveal only one "content" at a time’ is closed to new replies.