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 7842351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:17:58+00:00 2026-06-02T16:17:58+00:00

I am using twitter Bootstrap with jQuery and i was wondering how can i

  • 0

I am using twitter Bootstrap with jQuery

and i was wondering how can i toggle between “Subscribe / UnSubscribe”

Each click its an ajax request so the user can Subscribe / UnSubscribe

Once a user subscribed i display a messege “Subscribed!”
What about if a user regret and want to unubscribed?

I would like to have in one button both functionality.
I am changing the id dynamically but it doent work!

button class="btn" id="subscribe" data-toggle="button" data-loading-text="Loading..."  data-complete-text="Subscribed!">Subscribe
$(document).ready(function () {
        $('#subscribe').button();
        $('#unsubscribe').button();
    });




    $('#unsubscribe').click(function () {   
        $('#unsubscribe').button('loading');

        $.ajax({
            url: "<%= "#{root_url}unsubscribe_from/#{@collection.id}"%>" ,
            type: "GET",
            data: "",
            success: function(data) {
                $('#unsubscribe').button('complete');
                jQuery("#unsubscribe").attr("id","subscribe");
                jQuery("#subscribe").attr("data-complete-text").text("Subscribed!");
                }});
                return false;

            });


$('#subscribe').click(function () {   
    $('#subscribe').button('loading');
    // $('#subscribe').button('reset');
    $.ajax({
        url: "<%= "#{root_url}subscribe_to/#{@collection.id}"%>" ,
        type: "GET",
        data: "",
        success: function(data) {
            $('#subscribe').button('complete');
            jQuery("#subscribe").attr("id","unsubscribe");
            jQuery("#unsubscribe").attr("data-complete-text").text("Unsubscribe!");
            }});
            return false;

        });
  • 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-02T16:17:59+00:00Added an answer on June 2, 2026 at 4:17 pm
    $(document).on('click', '#subscribe, #unsubscribe', function(){
        var url; 
        var button_id; 
        var button_text; 
        var self = $(this);  
        self.button('loading');
    
       if( this.id === 'subscribe' )
        {
            url = "<%= "#{root_url}subscribe_to/#{@collection.id}"%>"; 
            button_id = 'unsubscribe';
            button_text = 'Subscribed!';  
        }
        else 
        {
            url = "<%= "#{root_url}unsubscribe_from/#{@collection.id}"%>"; 
            button_id = 'subscribe'; 
            button_text = 'Unsubscribed!'; 
        }
    
          $.ajax({
            url: url,
            type: "GET",
            data: "",
            success: function(data) {
                   self.button('complete');
                   self.attr("id", button_id);
                   self.attr("data-complete-text", button_text).text(button_text);
                }});
                return false;
    
          });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this link Link to another page using Twitter Bootstrap jquery modal in
I am using both JQuery Masonry and Twitter bootstrap together but experiencing a few
Using Twitter Bootstrap's bootstrap-tab.js, I have: <ul class=tabnavcenter id=myTab> <li class=active><a href=#home data-toggle=tab>about</a></li> <li><a
Using Twitter Bootstrap's [Tabbable Tabs][1], it says to: Enable tabbable tabs via javascript (each
Using the latest stylesheets from Twitter bootstrap 2.1.0, I can't get the navbars with
I am using twitter bootstrap rails with jQuery 1.7 When I load my project
I am using twitter bootstrap for a project - in particular its tab functions
I have just integrated my design built using twitter bootstrap, html5, css, jquery with
I am using twitter-bootstrap to develop a web application that can render on multiple
I am using twitter bootstrap and I would like a container div to stretch

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.