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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:08:16+00:00 2026-05-14T15:08:16+00:00

I am new to JQuery, so this may be a stupid question, however I

  • 0

I am new to JQuery, so this may be a stupid question, however I have not been able to find a solution.

I have a raw HTML string stored as a JS variable, as shown below. What I would like to do is parse the HTML string as a DOM object, and be able to access and change any children within the div by their id.

So, I would need to access “ht” and “vt” by id after the raw HTML is parsed. How would I perform this?

var htmlStr = "<div><span id='ht'>test 1</span><span id='vt'>test 2</span></div>";
$(htmlStr).ht // Something like this, that would return "test 1"

I am basically trying to use some raw HTML as a template for creating items in an unordered list. I would create the new list item using the template, and then replace certain portions of the template with data from a web service.

Thanks

  • 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-14T15:08:16+00:00Added an answer on May 14, 2026 at 3:08 pm

    Given your example, you could do.

    var htmlStr = "<div><span id='ht'>test 1</span><span id='vt'>test 2</span></div>";
    var htContent = $('#ht', htmlStr).text();
    

    Basically, you are getting an element with the ID of ht, from within the context of the <div> stored in your htmlStr variable.

    Then, you are retrieving its text content with .text(). Alternatively, you could retrieve any html tags as well with .html().


    EDIT:

    If you are going to do much work with that html string, you can store it in a jQuery object, and do whatever you want, even though it hasn’t yet been inserted into the DOM

    var $htmlStr = $("<div><span id='ht'>test 1</span><span id='vt'>test 2</span></div>");
    

    Now $htmlStr is a jQuery object, and you can manipulate it with the multitude of jQuery methods.

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

Sidebar

Related Questions

I'm new to jQuery so this may be a real simple answer. I have
I'm new to jquery, and sorry if this question is asked before (could find
hey people I'm new at jquery and i have been trying to figure this
Im super new to Jquery so this may be a quick one. I have
I'm rather new to jquery so this may be the issue. I have a
I'm kinda new to jQuery, so this may be a silly question... My problem
I am new to jQuery and so don't mind this question if it sounds
I am new to jquery so please excuse me if this question seems silly...
This may be a common problem but I'm struggling to find a solution that
Im new to rails so this may seem like a silly question but why

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.