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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:45:25+00:00 2026-05-23T16:45:25+00:00

I have a list (menu). When user clicks on link, I want to load

  • 0

I have a list (menu). When user clicks on link, I want to load content with ajax. The article to be loaded is to be determined based on the links id attribute.

example:

<ul class="ajaxMenu">
    <li><a id="services">Services</a>
    ...
</u>

the variables where I store the links to the article, are named the same as the links’ id (i.e. Services and the url for the ajax call is stored on var services)

This works:

var services = "index.php?option=com_content&view=article&id=2&tmpl=component";

jQuery(".ajaxMenu > li > a ").click( 
        function(event) { 

            jQuery("#contentComponent").load(services);

        }

    );

Since this line of code jQuery(this).attr(“id”) gives me id, I was hoping this would work [it did not work]:

var services = "index.php?option=com_content&view=article&id=2&tmpl=component";
var designs = "index.php?option=com_content&view=article&id=3&tmpl=component";
var contact = "index.php?option=com_content&view=article&id=2&tmpl=component";

jQuery(".ajaxMenu > li > a ").click( 
        function(event) { 

            jQuery("#contentComponent").load(jQuery(this).attr("id"));

        }

    );

I could create an if, or a loop, iterate through each var, (i.e. if jQuery(this).attr(“id”) == “services”…load(services))

but I suspect I can achieve this with simple elegant code.

How could I translate jQuery(this).attr(“id”) into the .load() function without having to if, loop, etc., the value of jQuery(this).attr(“id”) against the named variables where I stored the urls to be loaded?

  • 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-23T16:45:25+00:00Added an answer on May 23, 2026 at 4:45 pm

    I would firstly put href attributes into your links as it seems like a really good place to put them.

    <ul class="ajaxMenu">
        <li><a href="...">Services</a>
        ...
    </ul>
    

    And then in the click handler, do the load call using the href attribute. And don’t forget to call preventDefault to stop the click from actually reloading the entire page.

    jQuery(".ajaxMenu > li > a ").click(function(e) { 
        var href = jQuery(this).attr('href');
        jQuery("#contentComponent").load(href);
        e.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a separate navigation php which has a list of links and menu
I have a link for menu profile. It has a class called 'user-button'. When
I have a Menu. When user clicks on the menu , I need to
I'm having some trouble figuring this out. I have an unordered list menu that
I have a menu list something like this: <ul class=submenuList> <li><a onclick=loadItem('Blue%20Orchid%20Press') id=Blue%20Orchid%20Press>class=on>Blue Orchid
I have a list view filled with data. I set up a context menu
Here's my problem: I have do create a menu/list of actions (which would be
I have a simple list I am using for a horizontal menu: <ul> <h1>Menu</h1>
I have a simple unordered list with list items as menu item i created
I have a ul list that I display as a horizontal menu. I'd like

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.