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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:35:59+00:00 2026-05-21T22:35:59+00:00

I have this piece of html: <div id=1> <div class=text> Text for div 2

  • 0

I have this piece of html:

<div id="1">
  <div class="text">
     Text for div 2 
  </div>
<img src="images/image1.jpg"></img>
</div>

<div id="2">
  <div class="text">
    Text in div 2
  </div>
  <img src="images/image2.jpg"></img>
</div>

Which I grab with a simple .ajax-call

var html = $.ajax({
         url: "htmlsnippet.html",
         cache: false,
         async: false,
         dataType: "html"
         }).responseText;

If I filter it with:

var htmlFiltered = $(html).filter("#1");

it works just fine, I get the whole div with id=”1″,
but if I use:

var htmlFiltered = $(html).filter("#1 .text");

the htmlFiltered variable is an empty object.
I can’t figure out what I’m doing wrong.

  • 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-21T22:36:00+00:00Added an answer on May 21, 2026 at 10:36 pm

    You should store it this way:

    $.ajax({
       url: "htmlsnippet.html",
       cache: false,
       async: false,
       dataType: "html",
       success: function(data){
          html = data;
       }
    }
    

    EDIT: Your way of obtaining html works, but it’s not recommended.
    You can’t grab your last element because you’re using filter instead of find, so you should have:

    var htmlFiltered = $(html).find("#1 .text");
    

    instead of

    var htmlFiltered = $(html).filter("#1 .text");
    

    Also W3C recommends not to have numeric IDs.

    EDIT 2: This should work:

    var htmlFiltered = $(html).filter("#1").find(".text");
    

    Hope this helps. Cheers

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

Sidebar

Related Questions

I have this piece of HTML: <div class=embed> <iframe width=300 height=200 frameborder=0 allowfullscreen= src=http://www.youtube.com/embed/123456></iframe>
I have this piece of HTML <div id=fileTreeInviati> <ul class=php-file-tree> <li class=pft-directory> <a href=#
I have this piece of HTML code. <div class=tagWrapper> <i style=background-image: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/390945_10150419199065735_543370734_8636909_2105028019_a.jpg);></i> </div> I
I have this piece of html: <div id=parent> <div id=child></div> </div> and it looks
I have this simple piece of HTML code: <div> <input type=file name=english-file /> </div>
I have this piece of HTML code: <tr class=AttCardFooter onMouseOver=this.style.backgroundColor='#E1EAFE' onMouseOut=this.style.backgroundColor='Transparent'>...etc etc.. new lines
I have this piece of code: <li class=selected><a href=/AmIACandidate.html>Am I a Candidate?</a></li> I need
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
I have the following piece of HTML code: <div class=myclass id =class1> <ol class=list>

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.