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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:43:00+00:00 2026-05-22T20:43:00+00:00

I want to do the following. $(a).click(function (event) { event.preventDefault(); $.get($(this).attr(href), function(data) { $(html).html(data);

  • 0

I want to do the following.

$("a").click(function (event) {

    event.preventDefault();

    $.get($(this).attr("href"), function(data) {

        $("html").html(data);

    });

});

I want the behavior of all hyperlinks to make a ajax calls and retrieve the html.

Unfortunately you cannot simply replace the current html with the html you receive in the ajax response.

How can grab only what is within the <body> </body> tags of the ajax response so that i can replace only the contents of the body in the existing html.

Edit: the <body> opening tag will not always be just <body> it may sometimes have a class e.g.

<body class="class1 class2">

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

    If I understand you correctly, grab the content between the body tags with a regex.

    $.get($(this).attr("href"), function(data) {
        var body=data.replace(/^.*?<body>(.*?)<\/body>.*?$/s,"$1");
        $("body").html(body);
    
    });
    

    EDIT

    Based on your comments below, here’s an update to match any body tag, irrespective of its attributes:

    $.get($(this).attr("href"), function(data) {
        var body=data.replace(/^.*?<body[^>]*>(.*?)<\/body>.*?$/i,"$1");
        $("body").html(body);
    
    });
    

    The regex is:

    ^               match starting at beginning of string
    
    .*?             ignore zero or more characters (non-greedy)
    
    <body[^>]*>     match literal '<body' 
                        followed by zero or more chars other than '>'
                        followed by literal '>'
    
    (               start capture
    
      .*?           zero or more characters (non-greedy)
    
    )               end capture
    
    <\/body>        match literal '</body>'
    
    .*?             ignore zero or more characters (non-greedy)
    
    $               to end of string
    

    Add the ‘i’ switch to match upper and lowercase.

    And please ignore my comment regarding the ‘s’ switch, in JavaScript all RegExp are already single-line by default, to match a multiline pattern, you add ‘m’. (Damn you Perl, interfering with me when I’m writing about JavaScript! 🙂

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

Sidebar

Related Questions

I am trying to improve the following script a little: $(document).click(function(event) { $('.home.active').click(); $('.home').removeClass(active);
i want the following functionality. input : this is test <b> bold text </b>
I have the following markup: <button class=button type=button><span>Edit</span></button> I want to have a click
I have a parent window in which a push-button's click event function has the
How do i run a PHP function inside jQuery click event. I have the
I have the following javascript code. var Test = function(){ $(#+elementId).click(function(){ // How to
I want to the arr1 value is changed to arr2 value(test.php) when click event
Consider the following code: <div id=outer> <div id=inner></div> </div> $('#outer').click(function() { alert (outer); });
This works fine: $('.mainRotatorPaginator a').click(function() { $(this).everyTime(1000, 'rotation', function(i) { $('.mainRotatorPaginator').css('outline', '1px solid green');
I want the following layout to appear on the screen: FieldName 1 [Field input

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.