jQuery .click() bind an event handler to the "click" JavaScript event, or trigger that event on an element;
js:
$(function(){ $('.target').click(function() { // bind an event handler to the click event $(this).toggleClass('btn-primary'); $('.log').append(' click-event'); }); $('.trigger').click(function() { // trigger the click event manually $('.target').click(); $('.log').append(' click-trigger'); }); });
html:
<div class="well"> <p> <span class="target btn btn-primary">click me</span> <span class="trigger btn btn-inverse">click me to trigger click event manually</span> </p> <div class="log alert alert-block">log</div> </div>