jQuery method chaining is nothing but to make chain of methods i.e. in jquery we can call jquery methods one after the another. To chain method ,we can simply append the action to the previous action. When we chain jquery methods, the code becomes long. But jquery is not strict in syntax. We can format our code as per our choice.
In below code, we have form chain of fadeOut,fadeIn,slideUp and slideDown methods. So, action will be performed on <h1> elements as per provided sequence.
Full Code:-
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#btnClick').click(function(){
$('h1').fadeOut('2000').fadeIn('2000').slideUp('3000').slideDown('3000');
});
});
</script>
</head>
<body>
<h1>This is sample text.</h1><br/>
<button Id="btnClick">Submit</button>
</body>
</html>
No comments:
Post a Comment