EN
jQuery - hide and show element
1 points
In this article, we would like to show you how to hide and show elements using jQuery.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
5
</head>
6
<body>
7
<div id="text">This is example text...</div>
8
<button id="hide-text">Hide text</button>
9
<button id="show-text">Show text</button>
10
<script>
11
12
$(document).ready(function() {
13
var text = $('#text');
14
15
$('#hide-text').click(function() {
16
text.hide();
17
});
18
19
$('#show-text').click(function() {
20
text.show();
21
});
22
});
23
24
</script>
25
</body>
26
</html>
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
5
</head>
6
<body>
7
<div id="text">This is example text...</div>
8
<button id="hide-text">Hide text</button>
9
<button id="show-text">Show text</button>
10
<script>
11
12
var duration = 1000; // animation duration in milliseconds
13
14
$(document).ready(function() {
15
var text = $('#text');
16
17
$('#hide-text').click(function() {
18
text.hide(duration);
19
});
20
21
$('#show-text').click(function() {
22
text.show(duration);
23
});
24
});
25
26
</script>
27
</body>
28
</html>