Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:20:44+00:00 2026-05-17T23:20:44+00:00

Currently, I have a button called ‘Comment’ that when clicked slides down a comment

  • 0

Currently, I have a button called ‘Comment’ that when clicked slides down a comment box. I want the comment box to hide whenever the user clicks on any area of the page other than the comment box itself.

Currently, with my code the button just disappears when it is clicked. Could anyone point me in the right direction? Thanks!

Ruby ERB:

<% @entry.each do |e| %>
<div class="entry">
<p><%= e.entry %></p>
<small>Posted by <%= e.author %> at <%= e.created_at.strftime("%I:%M%p %m/%d/%Y") %></small>
<% if e.comments.nil? %>
    <p>No Comments</p>
<% else %>
    <% e.comments.each do |c| %>
    <div class="comment">
    <blockquote><strong><%= c.author %></strong> writes:<%= c.comment %></blockquote>
    </div>
    <% end %>
<% end %>
<div class="comments">
<a href="#" data-comment="<%= e.id %>" class="newcommentbutton">Comment</a>
<div class="newcomment" id="comment<%= e.id %>">
<%= form_for @comment, :url => entry_comments_path(e, @comment) do |f| %>
<ol>
<li><%= f.label :author %>
<%= f.text_field :author %></li>
<li><%= f.label :comment %>
<%= f.text_area :comment %></li>
<%= f.submit %>
</ol>
<% end %>
</div>
</div>
    </div>
<hr />
<% end %>
<%= button_to "Write A Message", new_entry_path, :method => :get %>

Javascript:

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function()
{
$('.newcommentbutton').click(function()
{
    var button = $(this);
    var comment = button.attr('data-comment');
    button.hide();
    $('#comment' + comment).slideDown('fast', function() {
        $('#comment' + comment + ' input[type=text]').focus();  
    });

});
$('.newcomment').click(function(event)
{
    event.stopPropagation();
});
$('body').click(function()
{
    $('.newcomment').hide();
});


});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:20:44+00:00Added an answer on May 17, 2026 at 11:20 pm

    Your new comment buttons also needs to stop propagation, like this:

    $('.newcommentbutton').click(function(e) {
        var button = $(this);
        var comment = button.attr('data-comment');
        button.hide();
        $('#comment' + comment).slideDown('fast', function() {
            $('#comment' + comment + ' input[type=text]').focus();  
        });
        e.stopPropagation();
    });
    

    You have the right idea, just remember that .newcommentbutton is also in <body> so it’s opening the comment form, then the click bubbles up and closes it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a delayed task that runs whenever I click a button. Clicking
I currently have my instance of Datepicker displaying the Button Bar panel that includes
I currently have a simple form that when you click the save button will
Currently have a drop down menu that is activated on a hover (from display:none
I have currently written a sub, written in VBA, that is called by the
I have an activity that I'm currently overriding the back button on in my
I have a view called Associations that has a drop down list and a
I currently have my code set to disable the submit button when the field
I currently have some code which when you press the submit button, a marker
I currently have this: function submit() { document.getElementById(lostpasswordform).click(); // Simulates button click document.lostpasswordform.submit(); //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.