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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:22:22+00:00 2026-06-12T09:22:22+00:00

How to extract html element into a variable after data is successfully returned from

  • 0

How to extract html element into a variable after data is successfully returned from an ajax response?

This is the ajax call containing the following returned data

   $.getJSON("test.php",function(data)
   {
        $.each(data, function(key, value)
        {
             alert(value); // this is working but don't know how to extract the strong element from the p element into a variable
        });
   });

I get the following html data returned from an ajax response

          <p id="testResults"><strong id="testNumber">Test 1</strong> passed - date </p>

How do I get the strong html element into a variable for later usage like this….

        var testNumberHtml = "<strong id='testNumber'>Test 1</strong>";

and then put the p element into another variable, like this…

       var testResultsHtml =  "<p id="testResults"> passed - date </p>";
  • 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-06-12T09:22:23+00:00Added an answer on June 12, 2026 at 9:22 am

    You might have to do a little trickery to separate those. I would suggest having server side send them separated like this:

    {p: "<p id="testResults"> passed - date </p>", 
     strong: "<p id="testResults"> passed - date </p>"}
    

    If that is not an option, you can probably do it like this in javascript:

    html

    <div id="contentResult" style="display:none;"></div>​
    

    js

    var jsonResult = '<p id="testResults"><strong id="testNumber">Test 1</strong> passed - date </p>';
    
    var jsonDiv = document.createElement("div");
    jsonDiv.innerHTML = jsonResult;
    var content = document.getElementById("contentResult");
    content.appendChild(jsonDiv);
    var strongElement = document.getElementById("testNumber");
    var strongCopy = $(strongElement).clone(true);
    strongElement.parentNode.removeChild(strongElement);
    var testResult = document.getElementById("testResults");
    var testCopy = $(testResult).clone(true);
    testResult.parentNode.removeChild(testResult);
    jsonDiv.parentNode.removeChild(jsonDiv);
    console.log(testCopy);
    console.log(strongCopy);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract data from HTML-files. The files in question are, most likely,
I have a html input element from which I need to extract the name
I have this XML file I need to extract the HTML Code from mono
I need to extract the src element from all image tags in an HTML
I want to make an AJAX call to an HTML-returning page, extract part of
I have a div element in an HTML document. I would like to extract
I am trying to use XPath to extract some HTML tags and data and
I have a big problem. I want to extract text from html table that
I have HTML that I need to extract a part number from, the HTML
I need to parse/extract information from an html page. Basically what I'm doing is

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.