how to show/hide divs when divs are created dynamically

I am developing comment systems with two level of replay to the comments and I have a problem with how to show and hide divs .., because it's id's are different .., I tried in a way with:


<span style="display:none;">
   <form action='' method='post' name="addcmt" onsubmit="return validate()">
        <textarea rows="1" cols="60" name='textarea1' id='textarea1' onKeyDown="limitText(this.form.textarea1,this.form.countdown,300);" 
       <input type="hidden" name="level1" id="level1" value="commtlevel1" />
       <input id='addcmt' type='submit' value='Add reply' name='submit'/> 

and jquery:

     $("button").click(function () {

but this way when I click reply button it shows all the span tag contente.., I wanna kow how I show one tag only or a way to my work done.



After edited question, i suggest you use div instead of span (because of display inline vs block).

$("button").click(function () {

would do the job how you want.Here is the result.


As there is no button in your HTML, it's partly a guess. But the following code will toggle the visibility of the span immediately following your button :

 $(document.body).on("click", "button", function () {

Note that you'd better define some classes to make the selector more selective :

 $(document.body).on("click", "button.toggler", function () {


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.