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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:53:33+00:00 2026-06-01T03:53:33+00:00

Could someone tell me why this code does not update the data response? It’s

  • 0

Could someone tell me why this code does not update the data response? It’s a simple example of the each function.

Here is the ajax requested html file:

<html>
<div class="new">
    <div class="span4">
        <h2>Heading1</h2>
        <p>Text1</p>
        <p><a href="#">Link1</a></p>
    </div>
    <div class="span4">
        <h2>Heading2</h2>
        <p>Text2</p>
        <p><a href="#">Link2</a></p>
    </div>
</div>
</html>

and here is the main file body:

<!DOCTYPE html>
<body>
<textarea id="gethtml" rows="40" cols="125"></textarea>

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
    "use strict";
    $(function() {

        $.get('file.html', function(data) {
            ajaxfunction(data);
        });

        function ajaxfunction(data) {
            $(data).find(".span4").each(function () {
                $(this).find("p").eq(0).text("Hello");
                $(this).find("p").eq(0).after("<p>newline</p>");
                console.log($(this));
            });
            $("#gethtml").val(data);
        }

    });
</script>
</body>
</html>

You can see that the console displays the correct data for each span4, but why doesnt the “data” string gets updated to reflect the changes?

EDIT

function ajaxfunction(data) {
            var tree = $("<div>" + data + "</div>");
            $(tree).find(".span4").each(function () {
                $(this).find("p").eq(0).text("Hello");
                $(this).find("p").eq(0).after("<p>newline</p>");
                console.log($(this));
            });
            $("#gethtml").val(tree.html());
}

This places in the textarea, ie <p>Hello</p><p>newline</p>.
So, in order to also put a new line into it, then I’ll have to modify it as a string, right?

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-06-01T03:53:34+00:00Added an answer on June 1, 2026 at 3:53 am

    data is a string.

    Your each code parses this string into a DOM tree and modifies it.
    However, you don’t do anything with this DOM tree.

    Your val() call uses the original string again.

    Instead, you need to call html() to get the source of the modified DOM tree.

    For more information, see my blog post.

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

Sidebar

Related Questions

Could someone please tell me why the Iterator in this code does not return
Could someone tell me if this: $.ajax({ url: 'test.html', success: function(data) { alert(Data Loaded:
Could someone tell me what is wrong with this code so doxygen cannot handle?
I've recently written this with help from SO. Now could someone please tell me
Could someone tell me what the units the SetTimeout(int) method in the ICriteria interface
Could someone tell me why the SSRS web service ReportService2005.asmx has a recursive parameter
Could someone tell me how the field Task Group is used in standard SharePoint
Could someone tell me how I can capture a NSParseErrorException? The Situation: my app
Could someone tell me how to view the XML to be sent via web
Could someone tell me what the purpose of inner classes are? Also when designing

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.