bambinou1980 Posted January 16, 2015 Share Posted January 16, 2015 Hello, I have 3 buttons on my website, I also have 3 divs with content in it(a lot of pictures in each). So imagine that when someone clicks on the button A, DIV A shows up but DIV B & C hide. What I am not too happy about is that I have noticed that even if the DIV are hidden, the whole graphics are loaded. Is there a way to put the content into other files and only load the files when the user request it please so I can then load the page empty(onload only). Thank you, Ben Quote Link to comment https://forums.phpfreaks.com/topic/293993-hide-and-show-is-different-files-how/ Share on other sites More sharing options...
cyberRobot Posted January 16, 2015 Share Posted January 16, 2015 You could dynamically create the image elements. When a button is clicked, you would unhide the corresponding <div>, create the necessary images with something like document.createElement(), and append the image elements to the <div> using something like Node.appendChild(). From there, you could just hide the <div> if another button is clicked. That way you don't have to load the images again. Quote Link to comment https://forums.phpfreaks.com/topic/293993-hide-and-show-is-different-files-how/#findComment-1503164 Share on other sites More sharing options...
cyberRobot Posted January 16, 2015 Share Posted January 16, 2015 Since it looks like you are using jQuery, you'll probably want to use .add() instead: http://api.jquery.com/add/ Quote Link to comment https://forums.phpfreaks.com/topic/293993-hide-and-show-is-different-files-how/#findComment-1503166 Share on other sites More sharing options...
CroNiX Posted January 16, 2015 Share Posted January 16, 2015 I'd just use ajax to retrieve the content. You could start with your first tab populated, and show the tab. The other tabs would be empty. When clicking on the other tabs, check to see if they're empty, and if so retrieve content via ajax. If not just display the tab normally. If user clicks on same tab again, it will already have the content and not fire the ajax request a 2nd time if (this_tab_content.html() == '') //nothing in tab yet { //fire ajax to retrieve content for this tab //success: function(response) { // this_tab_content.html(response.tab_html); //on ajax success, replace content of tab with resulting html //} } Quote Link to comment https://forums.phpfreaks.com/topic/293993-hide-and-show-is-different-files-how/#findComment-1503168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.