Jump to content

$().hide(); and .show() is different files - How?


Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/293993-hide-and-show-is-different-files-how/
Share on other sites

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.

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
  //}
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.