jQuery bind()

Introduction

Attach a click event to the <p> element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from w  w w  .j a  v  a  2  s  .  co  m*/
<script>
$(document).ready(function(){
  $("p").bind("click", function(){
    document.getElementById("demo").innerHTML = "The paragraph was clicked.";
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<p>Click me!</p>

</body>
</html>

The bind() method was deprecated in version 3.0. Use the on() method instead.

The bind() method attaches one or more event handlers for selected elements.

The bind() method set a function to run when the event occurs.

$(selector).bind(event,data,function,map)
Parameter
Optional
Description
event

Required.

one or more events to attach to the elements.
Multiple event values are separated by space.
data
Optional.
additional data to pass to the function
function
Required.
the function to run when the event occurs
map


Optional


an event map ({event:function, event:function, ...})
containing one or more events to attach to the elements,
and functions to run when the event occurs



PreviousNext

Related