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

  • Home
  • SEARCH
  • 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 678473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:09:13+00:00 2026-05-14T01:09:13+00:00

I call a certain div from another page with jquery to be loaded into

  • 0

I call a certain div from another page with jquery to be loaded into a div on my main page like this:

<script type="text/javascript">
$("#scotland").load("http://www.example.com/scotland .gallery");
</script>
<div id="scotland"></div>

The div I call is a piece of code which is automatically generated by a CMS made simple module, by the way.

Now it comes to my problem: The .gallery div I call, looks, a little simplified, like this:

<div class="gallery">
    <span><img src="http://www.example.com/scotlandimage1.jpg"></span>
    <span class="imgnavi"><a href="link_to_next_page_with_one_image">Next image</href></span>
</div>

I want the “next image”-link to load the next page into the .gallery div (it is always a page with one image on it). But what it does, is, it opens the new page http://www.example.com/scotland only.

I tried to use jquerys .live event to load the linked page (that would be “scotlandimage2” and the navigation, as you can see in the upper part – not only the image!), but I must have done something wrong. I tried different ways, but never got it to work. This was my last try:

$(".imgnavi a").click(function() {
  var myUrl = $(this).attr("href");
  $(".gallery").load(myUrl);
  return false;
});

I have to admit that I am very new to jquery… But does someone know what I did wrong (do I even follow the right handlers?)?

Thanks very much in advance!

Martin

  • 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-14T01:09:13+00:00Added an answer on May 14, 2026 at 1:09 am

    Your first attempt is good, but you’re missing the required-for-ajax call to live instead of click:

    $('.imgnavi a').live('click', function(ev) {
        // Stop regular handling of "click" in most non-IE browsers
        ev.preventDefault();
        ev.stopPropagation();
    
        // Load the new content into the div (same code you had)
        $('.gallery').load($(this).attr('href'));
    
        // Stop regular handling of "click" in IE (and some others)
        return false;
    }
    

    EDIT in response to the question: “What will happen with the old $('gallery') content?”

    With the above code, the old content will be replaced with the response to the .load() request. If you want to, say, prepend the image instead, you can just wrap the .load() call in a call to the built-in jQuery $.prepend( content ) method, like so:

    $('gallery').prepend($.load($(this).attr('href')));
    

    The same works for appending.

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

Sidebar

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.