I am trying o learn jQUERY , i am trying with different types of things in jquery .
I got this query , on click of a button , i am using the click funcion of a button to call another function , as shown .
But this isn’t working .
Could you please tell me , cant we use the click this way
$("button").click() instead of standard $("button").click(function(){
=====
This is my code
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" >
</script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click()
{
callMe();
}
});
function callMe()
{
$("p").hide();
}
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>
jQuery is a library built for the JavaScript language, not an actual language itself, and is thus restricted to what JavaScript lets it do.
So why the above won’t work is because
.click()is a method in jQuery that takes in arguments/parameters, not an actual part of the JavaScript language itself, which doesn’t let you use a block in that way.The function itself is an argument/parameter being passed to the
clickmethod. See if you can understand what’s going on this way:Or this way:
The above three code blocks would all cause
callMe()to be called when anything matchingbuttonis clicked.