Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Div disappear on click

    Hello guys,

    I got stuck with the following thing,
    For example: you see an div and when you click the div it will disappear (rather with the fadeOut), the problem was i could only find threads where you had to click an button or another div to make it fade out.
    Is this possible at all or do i need some way around it?
    i tried putting an href around the div (see below) but that didn't work either, any tips would be appreciated !

    $(document).ready(function() {
    $("a").click(function () {
    $("#wrapper").fadeOut("slow");
    });
    });

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    wouldn't that be

    Code:
    $(document).ready(function() {
    $("#id_of_the_div").click(function () {
    $(this).fadeOut("slow");
            });
    });
    (untested, but I reckon it's worth a shot)

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Nope, doesn't seem to work.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    works for me...
    Code:
    <!DOCTYPE html>
    <html>
        <head>
            <title>Demo</title>
    		<style type="text/css">
    			#id_of_the_div{
    			border:solid;
    			padding:5px;
    			cursor:pointer;
    			}
    		</style>
        </head>
        <body>
    		<div id="id_of_the_div">Click Me</div>
            <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    		<script>
    $("#id_of_the_div").click(function () {
    $(this).fadeOut("slow");
            });
    		</script>
        </body>
    </html>

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    I think the div's id is "wrapper" and the OP didn't change "id_of_the_div" accordingly and expected the script to work.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    Quote Originally Posted by glenngv View Post
    I think the div's id is "wrapper" and the OP didn't change "id_of_the_div" accordingly and expected the script to work.
    oh, yeah... that's probably it...

  • #7
    New Coder
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I'd change it, but probably something else is blocking it i assume, knowing it works for you it should for me anyways thanks a lot !

  • #8
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    Quote Originally Posted by DesignedbyLau View Post
    I'd change it, but probably something else is blocking it i assume, knowing it works for you it should for me anyways thanks a lot !
    I don't really know what that means but what glenn is saying is that you should just be able to drop this in and it will work:
    Code:
    $("#wrapper").click(function () {
    $(this).fadeOut("slow");
            });


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •