In this tutorial , we will discuss about how to hide boxes by clicking on it using jQuery. In the given below example , 30 boxes inside web page are displayed. When we click on any box (among these 30 boxes), it disappears and the next box (if any) shifts to left. These hide action is due to event click.
jqHideboxonclick.html
<!DOCTYPE html> |
Description of the program :
Inside "div" ,box is created using 'html' and it is replicated by using "for " loop inside 'script' as given below :
for (var i = 0; i < 30; i++) {
$("<div>").appendTo(document.body);
}
When we click on any box ,it would disappear due to following code :
$("div").click(function () {
$(this).hide(2000, function () {
$(this).remove();
});
});
OUTPUT

After clicking 15 boxes :

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.