Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:31:23+00:00 2026-06-14T11:31:23+00:00

With the following script I load a HTML document into a div-container and show

  • 0

With the following script I load a HTML document into a div-container and show it.
With the variable “x” I avoid that the document is reloaded with every click on the button.

The function to hide the container is missing here, as it has nothing to do with my question.

x = 0;
$('.button').click(function () {
    if (x == 0){
        $('.box').load('article.html', function () {
            x = 1;
            $('.box').fadeIn();
        });
    }else{
        $('.box').fadeIn();
    }
});

My question is, how do I have to change the script, if I have more buttons that load different documents?

The variable “x” has to work individually for all the buttons. Is there something like “this.variable” or am I wrong and I have to come up with something completely different?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:31:24+00:00Added an answer on June 14, 2026 at 11:31 am

    I would define the document to load in a data attribute. For example:

    <span class="button" data-doc="article.html">Load article</span>
    

    Then:

    $('.button').click(function(){
        var $this = $(this),
            $box = $('.box'),
            loaded = $this.data('loaded'),
            doc;
    
        if (loaded) { 
            $box.fadeIn();
            return; 
        }
    
        doc = $this.data('doc');
    
        $box.load(doc, function () {
            // mark it as being loaded
            $this.data('loaded', true);
            $box.fadeIn();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
The following java-script is working fine (Jquery) $(document).ready(function(){ $('#c_area').load($('.m_top:first').attr('href')) }); $('.m_top').click( function(){ $(#myDiv).html('<img src=images/loading.gif
I'm trying to load some xml and xslt stuff into this following html file:
When I run the following script, the event always fires on page load. I
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
Following Script isn't working in CHROME browser, IE is Fine. I've changed opener.document ...
The following script was recommended to use a List Page to show a Google
The following script is returning false, when I think that it should be returning
I am trying to load a bitmap into the canvas following the example here.
I use the following ajax code to load html page: var AJAX = {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.