SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Simple hide code not working

    Hello,

    I have simple code which shows a div and then on click it hides the div but its not working:

    Code:
    hidediv(divID)
    {
            var box = document.getElementById(divID);
            box.style.display = "none";
    }
    
    $(document).ready(function()
    {
            $("#notification").hide();
            $("#notification").load("#notification");
            $("#notification").slideDown("slow");
    });
    Code:
    <div id="notification"><a href="somelink.htm" onclick="javascript:hidediv('notification'); return false;" target="_blank"><img src="./images/chat_popup.png" border="0" /></a></div>
    How to fix this ?

    Thanks.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Your "hidediv" is not defined as function, you should do it like:
    Code:
    function hidediv(divID)
    {
            var box = document.getElementById(divID);
            box.style.display = "none";
    }
    
    $(document).ready(function()
    {
            $("#notification").hide();
            $("#notification").load("#notification");
            $("#notification").slideDown("slow");
    });
    But, seeing as you use jQuery, why don't you do it like so:

    Code:
    <div id="notification"><a href="somelink.htm" id="notificationlink" target="_blank"><img src="./images/chat_popup.png" border="0" /></a></div>
    Code:
    $(document).ready(function()
    {
            $("#notification").hide();
            $("#notification").load("#notification");
            $("#notification").slideDown("slow");
            $("#notificationlink").click( function() { $("notification").hide(); return false; } );
    });

  3. #3
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Thanks for the help. How to hide the div after 10 seconds ?

    Thanks.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Take a look at javascripts setTimeout() function.

  5. #5
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Your "hidediv" is not defined as function, you should do it like:
    Code:
    function hidediv(divID)
    {
            var box = document.getElementById(divID);
            box.style.display = "none";
    }
    
    $(document).ready(function()
    {
            $("#notification").hide();
            $("#notification").load("#notification");
            $("#notification").slideDown("slow");
    });
    But, seeing as you use jQuery, why don't you do it like so:

    Code:
    <div id="notification"><a href="somelink.htm" id="notificationlink" target="_blank"><img src="./images/chat_popup.png" border="0" /></a></div>
    Code:
    $(document).ready(function()
    {
            $("#notification").hide();
            $("#notification").load("#notification");
            $("#notification").slideDown("slow");
            $("#notificationlink").click( function() { $("notification").hide(); return false; } );
    });
    Hello,

    I tried the new code you provided and that is also not hiding the div.

    Thanks.


Bookmarks

Posting Permissions

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