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 8475511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:54:49+00:00 2026-06-10T17:54:49+00:00

I have three anchor tag links in my html with id’s switcher, switcher-b, switcher-c,

  • 0

I have three anchor tag links in my html with id’s “switcher”, “switcher-b”, “switcher-c”, when anchor tag “switcher” is clicked I would like to load content from a html page on my server “content.html”, anchor “switcher-b” will load “content-b.html”, and “switcher-c” will load “content-c.html”. I also have an anchor tag id “default” when clicked will reset / unload the html pages.

I figured a switch statement would be the best way to achieve my task but it is not working… I’m not proficient with jQuery/ JavaScript but I want to learn so if any JavaScript / jQuery developers with intermediate or advance knowledge can identify what I am doing wrong in my jQuery syntax and suggest a solution with explanation I truly will appreciate it.

Thank you for viewing my post and your help.

 <!-- HTML code -->

     <html>

        </head>
        <body>
        <h1>AJAX Calls with jQuery load()</h1>
        <div id="switcher">
        <p><a id="switcher" href="#">Click here to fetch HTML content</a></p>
        <p><a id="switcher-b" href="#">Click here to fetch HTML content</a></p>
        <p><a id="switcher-c" href="#">Click here to fetch HTML content</a></p>
        <p><a id="default" href="#">Reset</a></p>
        </div>

            <div id="result"></div>
</body></html>      




<!-- jQuery Code -->

            $(function(){

                $('#switcher a').click(function(event){
                    var bodyClass = this.id.split('-')[1];

                    $('body').removeClass().addClass('bodyClass');

                    switch(bodyClass){
                        case 'switcher':
                            $('#result').load('content.html #content');
                            break;
                        case 'switcher-b':
                            $('#result').load('content-b.html #content');
                            break;
                        case 'switcher-c':
                            $('#result').load('content-c.html #content');
                            break;
                        default:
                            $('#result').unload();
                    }
                    return false;
                });

            });

            </script>
  • 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-10T17:54:51+00:00Added an answer on June 10, 2026 at 5:54 pm
     $('#switcher a').click(function(event){
                        var bodyClass = this.id;
    
                        $('body').removeClass().addClass('bodyClass');
    
                        switch(bodyClass){
                            case 'switcher':
                                $('#result').load('content.html #content');
                                break;
                            case 'switcher-b':
                                $('#result').load('content-b.html #content');
                                break;
                            case 'switcher-c':
                                $('#result').load('content-c.html #content');
                                break;
                            default:
                                $('#result').unload();
                        }
                        return false;
                    });
    

    Just remove .split('-')[1] You are taking just a second part of id, after “-” and than testing for full id. Of course it will always to default

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

Sidebar

Related Questions

I have an anchor tag: <a href="file.pdf">Download Me</a> I would like for the user
I have some regular anchor tag links on my page that open up a
I have an one div inside that an anchor tag like this. <div onclick=page
I have an anchor tag in my HTML that is used for a javascript
This code is supposed to get the id from a clicked anchor tag in
Say I have an anchor on a webpage like so: <a name=comegetit></a> Is there
I have a simple .html page which uses Javascript to display some popups. Now
I have html output in paging section like this; <p>&nbsp;<strong class=active>1</strong>&nbsp;<a href=http://localhost/project/report_nc/search_now/1>2</a>&nbsp;<a href=http://localhost/project/report_nc/search_now/2>3</a>&nbsp;<a href=http://localhost/project/report_nc/search_now/1>Next
I would like to make all cells of an HTML table clickable--that is, the
I have a bunch of strings, each containing an anchor tag and url. string

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.