Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onclick on bootstrap button [duplicate]

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..

like image 357
iJade Avatar asked May 21 '13 11:05

iJade


2 Answers

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>
like image 73
Qurben Avatar answered Nov 16 '22 22:11

Qurben


<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

})
like image 25
Abraham K Avatar answered Nov 16 '22 22:11

Abraham K