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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:45:07+00:00 2026-06-10T23:45:07+00:00

I am loading a page inside of a div using ajax. It’s all working

  • 0

I am loading a page inside of a div using ajax. It’s all working fine when I have a fixed selector div such as –

$('.ajaxurl').click(function(){
    $('.selected-blog').load($(this).attr('href'));
    return false;
});

Here ‘.selected-blog’ is a fixed entry.

However I have multiple .ajaxurl links on the page, each with it’s own respective ‘.selected-blog’ div and so I want to be able to load the source into a different div depending on which .ajaxurl link was clicked. In other words, each .ajaxurl link will need to have a corresponding unique .selected-blog-[id] class and clicking the link will need to pass the [id] variable into the function so that it can be appended to the selector.

I have tried giving the .ajaxurl link an id to pass to the jquery as a variable, so that the body code is –

<div class="teaser-id<?php print $id; ?>">
  <a class="ajaxurl" id ="id<?php print $id; ?>" href="[pagelink]">Click me</a>  
  stuff here
</div> 
<div class="selected-blog-id<?php print $id; ?>"></div>     

[this above code repeats for each teaser in the list] 

And the jquery code is –

$('.ajaxurl').click(function(){
     var x = this.id;
     $('.selected-blog-,'+x).load($(this).attr('href'));
     return false;
});

But I can’t get it to work, what am I doing wrong?

(Finally – and this is an additional point for if it has an impact on the solution – I’d want to hide the teaser-[id] div, so if the variable passed can also be used for this .hide() function that would be great!)

How do I do this?!

Thanks very much!

  • 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-10T23:45:09+00:00Added an answer on June 10, 2026 at 11:45 pm

    You dont need to make your html so complex. You can keep it simple and use jquery next() to get the next div with the class selected-blog-id to load the content into.
    Something along these lines should work for you:

    HTML:

    <div class="teaser-id">
        <a class="ajaxurl" href="[pagelink]">Click me</a>  
        stuff here
    </div> 
    <div class="selected-blog-id"></div> 
    

    Javascript:

    $('.ajaxurl').click(function(e) {
        var $parent = $(this).parent();
    
        // hide the teaser
        $parent.hide();
    
        // load content into the next div with selected-blog-id
        $parent.next('.selected-blog-id').load(this.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 form loading inside my page and there is a button out
I am trying to run two scripts: one for loading page content using ajax
I'm loading a page dynamically via fancybox and AJAX. Everything is fine except when
I'm loading a page containing a GMaps using the ajax() method of jQuery. The
I'm loading using $.load() a .aspx page on a div of a parent .aspx,
I want to load content of my page inside a div element using this
i am loading a php page inside a div that takes a posted variable
I'm loading from DB some html (using ajax post request), it looks like: <div
i have a problem with loading .html pages (with JavaScript inside) into a div
I have a Help page, help.php that I am loading inside an iframe in

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.