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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:27:33+00:00 2026-05-18T08:27:33+00:00

When using the jQuery.ajax() method, I am struggling to filter the data that is

  • 0

When using the jQuery.ajax() method, I am struggling to filter the data that is returned to get exactly what I need. I know this is easy using .load() and probably the other jQuery AJAX methods but I need to use .ajax() specifically.

For example I know that this works;

var title = $(data).filter('title'); // Returns the page title

But what if I just want the contents of a div with id=”foo”?

var foo = $(data).filter('#foo'); // None of these work
var foo = $(data).find('#foo');   //
var foo = $('#foo', data);        //

Ideally, I want one method into which I can pass a normal jQuery selector, which will work for selecting titles, divs, or any other element that jQuery can select. This is so that I can pass in any string into my own ajax function – eg;

myApp.ajax({
    url: 'myPage.html',
    filterTitle: 'title',
    filterContent: '#main-content'
});

Any help would be greatly appreciated.

  • 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-18T08:27:34+00:00Added an answer on May 18, 2026 at 8:27 am

    The use of filter() vs. find() depends on the structure of your retrieved HTML page. For example, if this is the retrieved page:

    <!DOCTYPE html>
    
    <html>
    
    <head>
        <title>Foo</title>
    </head>
    
    <body>
        <div id="wrap">
            <div id="header">
                <h1>Foo</h1>
            </div>
            <div id="body"> content </div>
        </div>
        <div id="tooltip"> tooltip </div>
    </body>
    
    </html>  
    

    If you want to select the top-level elements = elements that are direct children of <body> – in this example: #wrap or #tooltip – then you have to use filter().

    If you want to select other elements – in this example: #header, <h1>, #body, … – then you have to use find().

    I you don’t know whether your element is a child of <body> or not, you could use this “hack”:

    $("<div>").html(data).find( selector );

    By using this work-around, you always get the elements via find().

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

Sidebar

Related Questions

I am using jquery ajax method to get data from a web method and
When using jQuery 's ajax method to submit form data, what is the best
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I make an AJAX request like so using JQuery: $.ajax({ type: GET, url: getvideo.php,
I am using jquery ajax method in my app and from the web method
I am using jquery ajax method on my aspx page to call a web
I am using jquery ajax method on my aspx page,which will invoke the webmethod
I have a c# web service that I call using jquery ajax. It works
I'm using jQuery's ajax methods to interact with the Twitter REST API . Their
I am using jQuery to invoke page methods for my AJAX calls using $.Ajax.

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.