Ben
Ben

Reputation: 6086

JQuery and Twitter Bootstrap "button" plugin - select value

I have the following HTML and would like to use Bootstrap's button plugin - http://twitter.github.com/bootstrap/javascript.html#buttons to select the "value" element:

<div class="btn-group pull-right nav-tabs" data-toggle="buttons-radio">
  <button class="btn" value="60">Hour</button>
  <button class="btn" value="1440">Day</button>
  <button class="btn" value="10080">Week</button>
  <button class="btn" value="43200">30 Day</button>
</div>

I have the following JavaScript that executes onClick successfully, but returns undefined.

$('.nav-tabs').button().click( function(e){     

  var selected = $(this).attr('value');

  console.log(selected);
});

Can anyone advise how I can get the "value" element from the html?

Upvotes: 3

Views: 6602

Answers (1)

Baylor Rae&#39;
Baylor Rae&#39;

Reputation: 4010

You're not selecting the button. It should look like this.

$('.nav-tabs').on('click', 'button', function(e){     

  var selected = $(this).attr('value');

  console.log(selected);
});

Upvotes: 10

Related Questions