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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:48:30+00:00 2026-06-01T04:48:30+00:00

I asked a precursor to this question here: Click link in DIV and show

  • 0

I asked a precursor to this question here:
Click link in DIV and show PHP/HTML in separate DIV

Then, after I removed the first script shown below, I was able to get the second script to work. I revised my question, but it appears to have gone silent. So I have a slightly modified question.

What is the conflict between the 2 scripts below and how can I modify them to work in tandem? Basically I want to be able to click anywhere in the DIV (“.side_items”) and have the child anchor links open in a separate DIV (“#main_content”)

Javascript:

<script type="text/javascript">
  $(document).ready(function(){ 
   $(".side_items").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
  })
 });
</script>

<script type="text/javascript">
  $(document).ready(function(){
   $(".side_items a").click(function(e){
    e.preventDefault(); 
       $("#main_content").load($(this).attr("href"));
    });
});

</script>

HTML: (slightly simplified)

<div id="main_content">
</div>

<div id="right_side">
  <div class="side_items">
  <a href="content.html">
  <img src="images/examplethumb.png" /><br />
  Content</a>
  </div>
</div>

Both scripts work independently to achieve their individual desired result.

  • 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-01T04:48:32+00:00Added an answer on June 1, 2026 at 4:48 am

    This will do it:

    $(document).ready(function(){  
        $(".side_items").click(function(){ 
            $("#main_content").load($(this).find("a").attr("href"));
            return false; 
        }) 
    });
    

    Breaking it down:

    $(".side_items").click(fn);
    

    Find all the elements with a class of side_items and assign a click event handler (fn) to them. Each time one of these elements is clicked, fn is executed with the context of the element. In the discarded code you were using the selector .side_items a, which meant the click handler was only bound to the links inside the div, not the div itself.

    $(this).find("a").attr("href")
    

    Find all the links that are contained within the current element (this), and get the value of the href attribute from the first element found. In the discarded code the context (this) was a link. Since our handler is now bound to the containing div, the context is also the div. To get the link you have to find it.

    $("#main_content").load(href);
    

    Find the element with an id of main_content and load the content found at href into it. In the discarded code you were setting location.href, which causes the page to navigate away.

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

Sidebar

Related Questions

I asked a similar question here where I wanted to get a single div
I asked this question earlier today. After trying out suggestions from a few members,
I asked and answered a question here that is related to this issue and
I asked this question before, Here however I think I presented the problem poorly,
I asked this question: Is ASP.NET MVC destined to replace Webforms? and a few
I asked this question earlier. I am intrigued by std::set but I have another
I asked a question here about an Linq error that results from mixing Linq-To-SQL
I asked this question on seomoz. http://www.seomoz.org/q/h1-tag and they recommend to put only h1
I asked this question earlier today and from the console, it works as expected.
I asked this question <input type="hidden" functionality issue a couple of days ago and

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.