Close div when clicked
Out of context: Reply #11
- Started
- Last post
- 25 Responses
- ********0
What I reckon you'll probably want to do though is only have the function get called when you click on specific things on a page.
For the sake of this example, I'm going to say you want an item called 'thingy' to fade out when you click on it, and for the code to be able to handle multiple 'thingy' instances.
in your HTML, give anything you want to hide when you click on it a class called 'thingy', like so:
<div class="thingy" id="object1"></div>
<div class="thingy" id="object2"></div>
<div class="thingy" id="object3"></div>then make a jQuery doc like so:
$(document).ready(function(){
$(".thingy").click(function(){
$(this).fadeOut(300);
});
});What you'll find is that even though there are multiple thingy object on the page, when you click the div with id 'Object 1', only object 1 will close.