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

  • Home
  • SEARCH
  • 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 9143741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:05:59+00:00 2026-06-17T10:05:59+00:00

Im using ajax to toggle a like button without a page refresh. For some

  • 0

Im using ajax to toggle a “like” button without a page refresh. For some reason when I click the button, in the background of the button it seems there are layers of bigger buttons. I don’t know why they are layering or why they would be larger sizes.

The issue is with the bootstrap class I’m using. It causes it to call btn over btn. When I remove the class the links rerender properly. Thus i tried to restyle the link_to in CSS to make it look like a btn however the same issue arose.

The is how the button normally looks:

enter image description here

After its been clicked:

enter image description here

enter image description here

Micropost/Helper:

def toggle_like_button(micropost, user)
  if user.voted_for?(micropost)
    link_to "undo", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"unvote_form_#{micropost.id}", :remote => true
  else
    link_to "Into it!", like_micropost_path(micropost), :class => "btn btn-mini btn-primary", :id =>"vote_form_#{micropost.id}", :remote => true
  end
end

Microposts/like.js.erb:

$("#vote_form_<%=@micropost.id%>").html("<%= escape_javascript(toggle_like_button(@micropost, @current_user)) %>")
$("#unvote_form_<%=@micropost.id%>").html("<%= escape_javascript(toggle_like_button(@micropost, @current_user)) %>")

Micropost Controller:

def like
  @micropost = Micropost.find(params[:id])
  @feed_item = Micropost.find(params[:id])
  if @micropost.user_id != @current_user.id
    if @current_user.voted_for?(@micropost)
      @current_user.unvote_for(@micropost)
      respond_to do |format|
        format.html { redirect_to :back }
        format.js
      end
    else
      @current_user.vote_for(@micropost)
      respond_to do |format|
        format.html { redirect_to :back }
        format.js
      end
    end
  end
end
  • 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-06-17T10:06:01+00:00Added an answer on June 17, 2026 at 10:06 am

    html(htmlString) sets the content of the selected element. Your selected element is the button. Use replaceWith(newContent) instead.

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

Sidebar

Related Questions

Im trying to toggle a button without refreshing using ajax In my micropost_helper.rb def
I'm using AJAX to get data for several business-card like divs on my page
I have a aspx Page where I am using AJAX. like <asp:UpdatePanel runat=server ID=upPanelDDLProgram>
Page using: jquery-1.8.0.min.js and jquery-ui-1.8.23.custom.min.js $( '#d-select' ).click(function() { $.ajax({ type: 'POST', url: 'ajax.php',
I'm using RichFaces' a4j:support to toggle the visibility of some controls on the page.
I have some functions to toggle 2 parts of an HTML if I click
I'm using asp mvc 2 and I have a page which has some data
This is followup question from my previous question Toggle button inside accordion using jquery
first post, im using the cakephp framework with ajax to create a reply button.
I'm using jQuery UI .toggleClass(class, [duration]) to toggle a red background on a 100x100

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.