简体   繁体   中英

Jquery show hide multiple times

I have a comment tree similar to Reddit's. People will need to be able to reply the comments by clicking a reply link, and then a form with a textarea should come. I tried using the .show() method, but there is more than one comment, and when you click reply it shows all the forms for every comment. How can i fix this? What should i look into?

  1. You'll need to set a class for each textarea (A different class for each one). Let's say:

    <textarea class="commentAnswerBox1">Answer here...</textarea>

  2. Now you have to set up a class for each comment answer button Like this

    <input type="button" class="btnAnswer1" value="Answer this comment" />

  3. Now you can call a function that recognizes which btnAnswer was clicked, and show only the correspondent commentBox .

You can use Class or IDs, or also create an attribute, it doesn't matter.

It seems to me that the issue stems from your DOM selector. It looks like you want to only show the last text area. If this is the case then you want something like

$('textarea:last').show();

Post more info so we can provide better answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM