31

Ok I'm new to bootstrap themes and all, so was trying to fire a javascript onclick method on the below bootstrap button but couldn't figure out how to do so..

<a class="btn btn-large btn-success" href="http://twitter.github.io/bootstrap/examples/marketing-narrow.html#">Send Email</a>

Any help would be appreciated..

Vini.g.fer
  • 11,093
  • 15
  • 55
  • 83
iJade
  • 21,874
  • 54
  • 150
  • 234

4 Answers4

47

Just like any other click event, you can use jQuery to register an element, set an id to the element and listen to events like so:

$('#myButton').on('click', function(event) {
  event.preventDefault(); // To prevent following the link (optional)
  ...
});

You can also use inline javascript in the onclick attribute:

<a ... onclick="myFunc();">..</a>
Qurben
  • 1,236
  • 1
  • 10
  • 20
1
<a class="btn btn-large btn-success" id="fire" href="http://twitter.github.io/bootstrap/examples/marketing-narrow.html#">Send Email</a>

$('#fire').on('click', function (e) {

     //your awesome code here

})
Abraham K
  • 625
  • 1
  • 8
  • 24
0

You can use 'onclick' attribute like this :

<a ... href="javascript: onclick();" ...>...</a>
EpokK
  • 37,948
  • 9
  • 59
  • 68
0

Seem no solutions fix the problem:

$(".anima-area").on('click', function (e) {
            return false; //return true;
});
$(".anima-area").on('click', function (e) {
            e.preventDefault();
});
 $(".anima-area").click(function (r) {
           e.preventDefault();
});
$(".anima-area").click(function () {
           return false; //return true;
});

Bootstrap button always maintain th pressed status and block all .click code. If i remove .click function button comeback to work good.