Jump to content

Javascript: show/hide div on linked page


Recommended Posts

I am displaying data from one page in another page in the following way:

<script>
    $(document).ready(function(){  
        $( "#2017" ).load( "data.html .2017" );
        $( "#2016" ).load( "data.html .2016" );
    });
</script>   

    <div id="2017"></div>
    <div id="2016"></div>

...BUT I also need to be able to hide (onload) certain div classes from within the linked file... 

<script>
    $(document).ready(function(){
        $('.private-files').hide();
    }); 
</script>   

I know that the code above will hide divs by class if they are contained in the main page, but how can I make it so that divs of class 'private-files' in 'data.html' will also be hidden?

Link to post
Share on other sites

The documentation for jQuery's load method is here:

http://api.jquery.com/load/

You can see from some of the examples that you can pass a callback function to load also.  The callback function gets called after the load has finished.  Inside that callback function you can run the code to hide the new elements that were just added.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...