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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:17:27+00:00 2026-05-12T15:17:27+00:00

I know how to hijack a link in jQuery, and I know how to

  • 0

I know how to hijack a link in jQuery, and I know how to find an element’s parent, but I can’t seem to combine the two. I have multiple divs, each of which contains a link. I want to hijack the link and update the parent div’s content.

<div class="container-1">
  <a href="/foo.html">Add content</a>
</div>
 <div class="container-2">
  <a href="/bar.html">Add content</a>
</div>

Here’s what I have with jQuery:

$(function() {
    $(".pager A").live("click",
    function() {
        $.get($(this).attr("href"),
        function(response) {
            $(this).parent().attr("id").replaceWith(response); // This is wrong
        });
        return false;
    });
});

The line with the “This is wrong” comment doesn’t have what I want for $(this). It appears to contain the result from the previous expression, not the element I selected (“.pager A”).

How can I do this?

Bonus question: Visual Studio complains that “.get is a reserved word and should not be used as an identifier”. What exactly is the problem?

EDIT: Sorry, I meant <div id="container-1">, not <div class="container-1">. Ditto for the 2nd div.

  • 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-12T15:17:27+00:00Added an answer on May 12, 2026 at 3:17 pm

    Try saving the reference to the current execution context where it points to the anchor to refer to later in the callback:

    $(function() {
        $(".pager A").live("click",
        function() {
            var el = this;
            $.get($(el).attr("href"),
            function(response) {
                $(el).parent().html( response ); // is this what you want? .attr('id') would return a string and you can't call jQuery methods on a string.
            });
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know jquery have backwardscompatibility files. But if you link to this specific version:
I know, I would have thought the answer was obviously no as well, but
I know there are similar questions already on SO but none of them seem
I know regex and substrings is a common question on here but i can
I know the input have the maxlength, but I would like to have minlength
I know that you can store a bunch of Parent* objects in a vector.
I know we can trigger an Intent.ACTION_SEND intent to send email. But according to
Anyone know where I can find a C# implementation of eksblowfish crypt? Thanks
I'm just curious to know how jQuery is able to hijack the 'this' keyword
I know this topic has been discussed a lot , but I have a

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.