Jquery bind() Method

Event bind() method adds to matched or selected elements. here we have example about bind()method, this method when the uses clicks on button binds the click event to button(with id of #clickMe) then alert will of text.

Jquery bind() Syntax


Single Event Binding code

 //html code button code
<button id="clickMe">Click me</button>

//jquery bind() method code
  $("#clickMe").bind( "click", function() {
  alert( "Hay Hello! Clicked on button" );

Multiple events binding code

Multiple events can bound by using space to separate. we have couple of events (mouseenter and mouseleave), The effect of this on <div class="main"> (when it does not initially have the " temporary " class) is add the temporary class when the mouse enter the div and remove when the mouse leaves.

//html code
<div class="main">simple div tag<div>

$( ".main" ).bind( "mouseenter mouseleave", function() {
  $( this ).toggleClass( "temporary" );