jquery .on() toggle div

Posted by lollo on Stack Overflow See other posts from Stack Overflow or by lollo
Published on 2012-10-17T22:54:43Z Indexed on 2012/10/17 23:00 UTC
Read the original article Hit count: 180

Filed under:

i'm developing a blog with dynamic content loaded via ajax request and i'm trying to hide/show the "post comment" form, of the article, with a button :

<div id="post">
...
  <ol id="update" class="timeline">
    <!-- comments here -->
  </ol>
  <button class="mybutton Bhome">Commenta</button><!-- hide/show button -->
  <div class="mycomment"><!-- div to hide/show -->
    <form action="#" method="post">
      Nome:
      <input type="text" size="12" id="name" /><br />
      Email:
      <input type="text" size="12" id="email" /><br />
      <textarea rows="10" cols="50" class="mytext" id="commentArea"></textarea><br />
      <input type="submit" class="Bhome" value=" Post " />
    </form>
  </div><!-- mycomment --> 
</div><!-- post -->  

This jquery code works well but has effect on All the posts...

$("div").on("click", ".mybutton", function(e){ 
  $(".mycomment").slideToggle("slow");
  e.stopPropagation();
});

I want that only the clicked hide/show button has effect on the related article but f i have more than one article on my page the button with .mybutton class hides or shows all the comment form of all the articles.

© Stack Overflow or respective owner

Related posts about jQuery