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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:35:33+00:00 2026-05-29T20:35:33+00:00

Update: I did get this working, here is the new javascript: $(document).ready(function() { $(‘a’).click(

  • 0

Update:

I did get this working, here is the new javascript:
$(document).ready(function() {

$('a').click( function(e) {
    $v = $(this).attr("class");
    $targetID = ' #' + $v; 
    $path = $(this).attr('href') + $targetID;
        $('#' + $v).load($path); 
    e.preventDefault();     
});

What happened was that I wasn’t realizing $path was already taking into account what I was searching for, #CLASS-NAME. I had it set up to search for #class-name inside of #class-name. Thanks for your help!

Original Post:

I’m trying to teach myself how to better take advantage of ajax with jQuery, so I’m updating my portfolio to update content dynamically. This test simplifies the process, but for this case I have 3 html pages:

    home.php
    about.php
    contact.php

with identical markup, but only their respective div containing content:

    <div id="links">
       <a href="../ajax/home.php" class="home">Home</a>
       <a href="../ajax/about.php" class="about">about</a>
       <a href="../ajax/contact.php" class="contact">contact</a>
   </div>

   <div id="content">
       <div id="home">
           <p>Home</p>
       </div>
       <div id="about">
       </div>
       <div id="contact">
       </div>
   </div>

So home.php contains a paragraph in #home that says ‘home’. Trying to keep it simple and boring.

Here is the javascript involved:

    $(document).ready(function() {
        $('a').click( function(e) {
            $v = $(this).attr("class"); //pulls the name of the associated link
            $targetID = ' #' + $v; 
            $path = $(this).attr('href') + $targetID; //generates the path that ajax is loading: "../folder/FILE-NAME/.php #DIV-NAME"
            if ($('#', $v).text() == '') {  //Checks whether content exists in that div already     
                $('#', $v).load($path + ' ' + $targetID); //Is SUPPOSED to pull content from the div on one page into its corresponding div on the current page - This is where the script is breaking
            }
            else {
                alert($v + " isn't empty!");
            }
            e.preventDefault(); //prevents normal link behavior
        });
    });

The part where the script is breaking is of course the part I’m just learning to use – the ajax request to load the content from one div on a different page and putting it into the right div on the current page.

Can someone point out my mistake(s)?

  • 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-29T20:35:35+00:00Added an answer on May 29, 2026 at 8:35 pm

    You are selecting your content divs wrong:

    $(document).ready(function() {
        $('a').click( function(e) {
            $v = $(this).attr("class"); //pulls the name of the associated link
            $targetID = ' #' + $v; 
            $path = $(this).attr('href') + $targetID; //generates the path that ajax is loading: "../folder/FILE-NAME/.php #DIV-NAME"
            if ($('#' + $v).text() == '') {  //Checks whether content exists in that div already     
                $('#' + $v).load($path + ' ' + $targetID); //Is SUPPOSED to pull content from the div on one page into its corresponding div on the current page - This is where the script is breaking
            }
            else {
                alert($v + " isn't empty!");
            }
            e.preventDefault(); //prevents normal link behavior
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fair warning: I am no expert, but I did manage to get this far.
Update take 2 here is the two queries i'm working with (paging is omitted
Update: Ok, after getting past the fact that I did not have MSDTC set
Is it possible to bulk update? I did a build insert, now I would
Update: Solved, with code I got it working, see my answer below for the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
I've been working to get our site moved to a public beta server, and
One of the nastiest problems working across time zones :) Here is my problem:

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.