Jump to content

href to open, href to close and open


TeddyKiller

Recommended Posts

I have an href for "View Comments" what should happen is when you click that.. a div underneath should display the comments etc.. (stick with the div because I can do the rest)

This is simple

however.. there may be multiple "view comments" for different posts.

I could use a javascript function. Do an onclick href event, and call the function with the div name. Multiple divs will be used (It's in a while function) what I'd do.. is do specific ID's relating to the while. Allowing the divs to have different names. comment-1, comment-2 for example.

 

Sorry if I'm confusing you. This will allow me to have multiple comment divs, although I would like to close every other div thats open.

 

So.. href to open 1 div. When you click on another href to open another div, it'll have 2 divs open. When I only want it to open once at a time.

If I make sense.

 

How can I do it? If i've had no replies by the time I finish the first bit.. i'll post the code.

Link to comment
Share on other sites

This would be the php. The onclick calls the function "showComments" with the comment id. (Unique for that post)

The div to be displayed, also has the unique ID. So when the javascript function gets called.. It'll open the div.

echo '<a href="#" onclick="showComments(\'comment'.$row['id'].'\')">View Comments(0)</a>' . 
'<div id="comment'.$row['id'].'" style="display:none;"> stuff </div>';

 

Javascript for the function

function showComments(Comment_Menu) {
Comment_Menu = document.getElementById(Comment_Menu);
if(Comment_Menu.style.display == "none") {
	Comment_Menu.style.display = "block";
}
}

 

This works for multiple divs. (The echo is in a while function, so it gets displayed multiple times, each one having different div id)

Although.. what I want is that when a div opens, all remaining divs that are opened, to be closed.

 

Hope this makes more sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.