Slide up and down of a div animates its content - jQuery?

jQueryWeb DevelopmentFront End Technology

To toggle content, use slideToggle() in JavaScript.


Following is the code: −

 Live Demo

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
   .firstDiv {
      display: none;
   .txtBox {
      display: block;
   <button onclick="toogleTheTextBox()">Press Me to toggle the text box</button>
   <div id='firstDiv'>
         Enter your name:<input type='text' id='txtBox' />
   function toogleTheTextBox() {
      $('#firstDiv').slideToggle(function () {

To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.


The output is as follows −

Press the button “Press Me” to toggle the text box.


The output is as follows −

Updated on 03-Oct-2020 13:13:52