Reputation: 91
How do I call an other function using jquery , I have tried all methods and all failed,
I have an example using the slide function of jquery api script I need to call a function afer the sliding is over but i am not able to execute the simple function complete()
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".flip").click(function(){
$("#panel").slideToggle(["slow"][,complete]); // i need to call the complete function
function complete(){alert("hello");}
});
});
</script>
<style type="text/css">
#panel,.flip
{
padding:5px;
text-align:center;
background-color:#e5eecc;
border:solid 1px #c3c3c3;
}
#panel
{
padding:50px;
display:none;
}
</style>
</head>
<body>
<div class="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>
</body>
</html>
I have used this example from w3schools
http://w3schools.com/jquery/tryit.asp?filename=tryjquery_slide_toggle
Upvotes: 0
Views: 1010
Reputation: 992
You can also directly include a function as a statement:
$("#panel").slideToggle("slow", function() {
// things to happen AFTER the slide is finished
})
);
Upvotes: 1
Reputation: 10003
Correct syntax is:
$(document).ready(function(){
$(".flip").click(function(){
$("#panel").slideToggle("slow", complete);
function complete(){alert("hello");}
});
});
[]
are used just to denote that the argument is optional.
Upvotes: 1