• We just launched and are currently in beta. Join us as we build and grow the community.

How to Show/Hide Div Tag and Set Time out using JQuery

mrhaha

Anime Night Host
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
153
Likes
160
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial, I'm going to show you how to show/hide an area in the page without reloading the whole page using JQuery. I've also included in this tutorial a sample loader and a time out for the loader. Be sure to download the included sample gif and sample jquery.

Creating our Page

We create our page that includes our jquery. To create the page, open your HTML editor and paste the code below. We name this as our "index.php".

  1. <!

    DOCTYPE html>
  2. <

    html>
  3. <

    head>
  4. <

    title>

    Show/

    Hide Tutorial with Loader using JQuery</

    title>
  5. </

    head>
  6. <

    body>
  7. <

    h2>

    Hide and Show Tutorial</

    h2>
  8. <

    div id=

    "sample"

    >
  9. <

    h1>

    HIDE ME!</

    h1>
  10. </

    div>
  11. <

    button type=

    "button"

    id=

    "hide"

    >

    Hide</

    button>

    <

    button type=

    "button"

    id=

    "show"

    >

    Show</

    button><

    br><

    br>
  12. <

    h2>

    Loader with Time out</

    h2>
  13. <

    button type=

    "button"

    id=

    "loader"

    >

    Show Loader</

    button>
  14. <

    div id =

    "loader_here"

    ></

    div>
  15. <

    script src =

    "jquery-3.1.1.js"

    ></

    script>
  16. <

    script type =

    "text/javascript"

    >
  17. $(

    document)

    .ready

    (

    function

    (

    )

    {

  18. $(

    document)

    .on

    (

    'click'

    ,

    '#hide'

    ,

    function

    (

    )

    {
  19. $(

    '#sample'

    )

    .hide

    (

    )

    ;
  20. }

    )

    ;

  21. $(

    document)

    .on

    (

    'click'

    ,

    '#show'

    ,

    function

    (

    )

    {
  22. $(

    '#sample'

    )

    .show

    (

    )

    ;
  23. }

    )

    ;

  24. $(

    document)

    .on

    (

    'click'

    ,

    '#loader'

    ,

    function

    (

    )

    {
  25. $(

    '#sample'

    )

    .show

    (

    )

    ;
  26. var

    loader =

    $(

    '<img src = "loader.gif" height="200px;" width="200px;"/>'

    )

    ;
  27. loader.appendTo

    (

    $(

    '#loader_here'

    )

    )

    ;
  28. setTimeout(

    function

    (

    )

    {
  29. loader.remove

    (

    )

    ;
  30. }

    ,

    5000

    )

    ;
  31. }

    )

    ;
  32. }

    )

    ;
  33. </

    script>
  34. </

    body>
  35. </

    html>


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,348

323,357

Top