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

  • Home
  • SEARCH
  • 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 9053277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:23:10+00:00 2026-06-16T13:23:10+00:00

I am trying to dynamicaly load specific html files into a container DIV with

  • 0

I am trying to dynamicaly load specific html files into a container DIV with a single onclick function instead of one for each button.

I am pretty new to this (it’s my first time working with AJAX or JQuery) and this is what I managed to come up with so far.

$(document).ready(function(){

$("#container").load("home.html");

$("#home").click(function(){
    $("#container").load("home.html");
});
$("#news").click(function(){
    $("#container").load("news.html");
});
$("#about").click(function(){
    $("#container").load("about.html");
});
$("#contact").click(function(){
    $("#container").load("contact.html");
});
});

As you see, for now I have 4 buttons with unique IDs and a function for each of them. But what I’d like to do is to simplify this and create a single function that takes each button’s ID and uses it as the URL for the page to load in the container. So that URL = ID + “.html”.

This would help me avoid having to add script with every new entry on my portfolio.

Anyone has any ideas on how I can do this?

Thanks!

  • 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-16T13:23:11+00:00Added an answer on June 16, 2026 at 1:23 pm

    You could do this :

    $("#home, #news, #about, #contact").click(function(){ 
        $("#container").load(this.id+".html");
    }
    

    But the right thing to do would be to use an attribute instead of an id :

    <div link=home>something</div>
    ...
    $("[link]").click(function(){ 
        $("#container").load($(this).attr('link')+".html");
    }
    

    Then you wouldn’t have to change your selector each time you add a link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery 1.5.2 trying to dynamically load a div from one source into
I'm trying to load content into a Dojo content pane in a specific html
I'm trying to dynamically load html into a popup using ajax with this: $('body').load(
I am trying to use jQuery's .load function to dynamically load content into my
I'm trying to dynamically load an image into a div by clicking on another
I'm trying to dynamically load values into a select in a jqGrid. It almost
I am trying to load assets from an SWC into a SWF at compile
I'm trying to dynamically load a camera library .so file into a Linux executable
I am trying to dynamically load a KML file into a map depending on
So I'm trying to dynamically load a usercontrol into a placeholder in another usercontrol

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.