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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:07:51+00:00 2026-05-23T15:07:51+00:00

I have a jQuery tab script that gets content from a PHP file defined

  • 0

I have a jQuery tab script that gets content from a PHP file defined by the link and parses it to a div element. The ID for each link is used to pull content from the correct file however type_ is needed in the link ID for the tabs to work which then doesn’t pull content from the right place. How can I resolve this issue?

This is my current jQuery code:

function load(url){
    $.ajax({
        url:url,
        success:function(message){
            $("#content").html(message);
        }
    });
}

$(document).ready(function(){
    $("[id^=type_]").click(function(){
        type=$(this).attr("id");
        url=""+type+".php";
        $("[id^=type_]").removeClass("selected");
        $("#"+type).addClass("selected");
        load(url);
        return false;
    });
    $("#type_search").click();
});

This is my HTML code:

<ul> 
<li><a id="type_tab1" href="javascript:void(null);">Tab1</a></li> 
<li><a id="type_tab2" href="javascript:void(null);">Tab2</a></li> 
<li><a id="type_tab3" href="javascript:void(null);">Tab3</a></li> 
</ul>
  • 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-05-23T15:07:52+00:00Added an answer on May 23, 2026 at 3:07 pm

    From your description, I assume you mean the content is located at tab1.php, tab2.php, etc and the problem is with your type_ prefix in the ID.

    Option #1 – Most like your code

    I don’t think you need type_ in the id. Seems like you could accomplish the same thing with a class='tab' on each of your anchors like

    <li><a id="tab1" class="tab" href="javascript:void(null);">Tab1</a></li> 
    

    and then do

    $('.tab').click(function() {
        var tabId = $(this).attr("id");
        var url=""+tabId+".php";
        $('.tab').removeClass("selected");
        $('#' + tabId).addClass("selected");
        load(url);
        return false;
    }
    

    Option #2 – Cleaner and makes more sense

    There’s no reason to overload the ID attribute with the url of your content. Try:

    <li><a id="tab1" class="tab" href="/path/to/content/tab1.php">Tab1</a></li> 
    

    Normally, this would take you to the content, but you can prevent the default behavior by:

    $('.tab').click(function(event) {
    
        // Prevent actually going to the content
        event.preventDefault();
    
        // Adjust tabs
        var $currentTab = $(this);        
        $('.tab').removeClass("selected");
        $currentTab.addClass("selected");
    
        // Load content from the href attribute of the tab          
        load($currentTab.attr("href"));
    
        return false;
    }
    

    Option #3 – This is already a JQuery Extension

    Have you considered using JQuery UI Tabs? http://jqueryui.com/demos/tabs/ I’ve found the demo site to be a bit wonky sometimes, but JQuery UI is very popular, stable, and flexible. There is an option to load content via AJAX.

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

Sidebar

Related Questions

I have some jQuery code. I have called an Ajax function file, file.php, that
I have a jquery script that attaches a click event to every link, running
I have this script that creates a new tab in JQuery. Can you check
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
With help from you guys I now have a script that works like a
I have to make an iframe element from java script so it isn't scrollable
Using jQuery UI , I have a tabs plugin and within tab 1 gets
I have a page with tabs on it that you this jQuery script http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
Say I have jquery code like this: html += '<div class=index>' + item.index +
I have some jQuery/JavaScript code that I want to run only when there is

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.