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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:54:35+00:00 2026-05-22T12:54:35+00:00

I tried this code: $.post(‘/script’, function(result) { var foo = $(result).find(‘#foo’); $(‘#result’).html(foo); }); Here’s

  • 0

I tried this code:

$.post('/script', function(result) {
    var foo = $(result).find('#foo');
    $('#result').html(foo);
});

Here’s the return html:

<div id='foo'>
  Content.
</div>
<div id='new'>
   New data
</div>

After alerting variable foo it returns an object. And the html becomes empty. I would like to print a specific html block (#foo only not #new).

From jQuery documentation:

$.post( url, { s: term } ,
      function( data ) {
          var content = $( data ).find( '#content' );
          $( "#result" ).html( content );
      }
);

This (var content) would also result to object and printing an empty string on #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-05-22T12:54:36+00:00Added an answer on May 22, 2026 at 12:54 pm

    This happens because both #foo and #new are at the top level.

    The .find() method looks for descendants. so you will need to wrap them in another div either at the server-side (result) or the jQuery level.

    So either change html to

    <div>
       <div id='foo'>
         Content.
       </div>
       <div id='new'>
          New data
       </div>
    </div>
    

    or at jquery level

    $.post('/script', function(result) {
        var foo = $(result).wrapAll('<div>').parent().find('#foo');
        $('#result').html(foo);
    });
    

    If you use the HTML solutions you could however use the .load method which can load page fragments

    $('#result').load('/script #foo');
    

    This will load the element with id foo from the /script page and put it in #result element.

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

Sidebar

Related Questions

I found this code on here from this post: jQuery Accordion: links don't work
i'm using this code to post to a php page: var qreq = .....myurl.php;
I copied this code from another post. I tried the example, however, I am
When I run this code the selected item is not visible. I've already tried
Edit: Of course my real code doesn't look exactly like this. I tried to
I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item(Post), \b\#\b) But it is
I've honestly tried this left and right and still find that my mirror server,
I'm using the source code found on this site here: http://webtint.net/tutorials/5-star-rating-system-in-php-mysql-and-jquery/comment-page-1/#comment-2562 A fantastic resource,
i am using this code to upload files(images to a folder) <form action='' method='POST'
UPDATE2: i tried this piece of code, but still no echo, i valued my

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.