0

I'm using bootstrap and trying to use loading state to make the main button to show "loading..." hen the dropdown links are clicked.

HTML codes

<div class="btn-group">
  <a href="#" data-toggle="dropdown" class="btn dropdown-toggle" id="test">
    Set
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <!-- dropdown menu links -->
    <li><a class="paid-today">Paid today</a></li>
  </ul>
</div>

Javascript

$(function() {
  $( ".paid-today" ).click(function() {
    var $this = $(this);
    $this.closest("a").button('loading');
  });
});

When I did this, the dropdown link changed to "loading..." instead, not the main button.

2
  • your selectors are wrong. are you trying to change the text "Set" to "loading"? Commented Aug 3, 2013 at 12:08
  • Which is main button? Commented Aug 3, 2013 at 12:09

2 Answers 2

2

Try to target the button with a selector in

$( ".paid-today" ).click(function() {
    // here
});

If '#test' is the one you meant, use

$('#test').button('loading');

Or if you want to change the one you clicked,

$(this).button('loading');

I don't know what plugin you are using, but if it's just some styled link, you can simply use .text("loading"); instead of .button(...

Sign up to request clarification or add additional context in comments.

1 Comment

Why are you specifying a tagname with an ID? Edit: better, don't want to encourage bad habits
0

try this

    $(function() {
       $( ".paid-today" ).click(function() {
         var $this = $(this);
         $this.closest("ul").prev().button('loading');
      });
    });

1 Comment

Emerson F, forget it! =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.