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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:02:57+00:00 2026-05-16T05:02:57+00:00

In the application that we have, we’re doing some AJAX response. Once in a

  • 0

In the application that we have, we’re doing some AJAX response. Once in a while we get back a response that isn’t fully contained Test 3 in the code below. While it’s possible to beat people into submission, I would like to just build in some belt and suspenders in the code to handle the case.

The key is the findself() function which is designed to take any response html block via the $(‘…html…’) string and then do the appropriate magic to it. This works just find for some cases, but in case #3 it dies with a getAttribute error in the browser.

Any good ideas of how to extend the findself() function to handle case #3?

var html;

function findself(sel, html) {
    return html.is(sel) ? html.find(sel).add(h) : html.find(sel);
}

html = $('<span rel="toggle">foo</span>');

findself('[rel="toggle"]', html).each(function () {
    console.log('ok 1');
});
console.log('done case 1');

findself('[rel="toggle"]', $('testing of a text node')).each(function () {
    console.log('ok 2');
});
console.log('done case 2');

html = $('<span>foo</span>some text<div rel="toggle">xx</div>');

findself('[rel="toggle"]', html).each(function () {
    console.log('ok 2');
});
console.log('done case 3');
  • 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-16T05:02:58+00:00Added an answer on May 16, 2026 at 5:02 am

    Quick version: You can side-step your current issue by ensuring that text element isn’t in-between 2 ones and at the root, like this:

    function findself(sel, html) {
        var h = $("<div />").append(html);
        return h.is(sel) ? h.find(sel).add(h) : h.find(sel);
    }
    

    You can test it out here.


    Explanation: This is a bug in jQuery core it looks like. It’s detecting it as a HTML string, because of the opening/closing tags, but it’s not a single element. It’s 3 nodes one being a text, due to this incorrect detection it’s incorrectly treating it as an element string, rather than a collection of children, for example:

    jQuery.filter('[rel="t"]', $('<span>foo</span>some text'));            //works
    jQuery.filter('[rel="t"]', $('<div><span>foo</span>some text</div>')); //works
    jQuery.filter('[rel="t"]', $('<span>foo</span>text<div>xx</div>'));    //fails
    

    So currently, jquery.filter() (which .is() uses) doesn’t work with a text node in the middle.

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

Sidebar

Related Questions

I have an application that uses the old REST API call Friends.getAppUsers to get
I have a c# simple application that have to write some values in a
I have a home page in JSP of my MVC application that have some
I have a Windows Mobile Desktop Application that have some text fields which will
I have an iPhone application that pulls some JSON data from a server and
I want to get all emails in my ASP.NET application that have a certain
I am writing an application that writes to SQL Compact files that have a
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
I'm currently writing a web application that have about 6-12 pages. On each one
I have a group of radio buttons in my Swing application that 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.