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

  • Home
  • SEARCH
  • 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 6047369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:20:37+00:00 2026-05-23T07:20:37+00:00

I have an ajax call returning various database fields one-by-one in a for loop.

  • 0

I have an ajax call returning various database fields one-by-one in a for loop. I’m able to test if the field is HTML by using:

for(i = 0; i < copyFromSchedule.length; i++) {
    temporaryString = $(this).attr("ows_"+copyFromSchedule[i]);
    if ($(temporaryString).html() == null)
        // Is not HTML...
    else
        // Is HTML, remove any anchors found in this string (<a name="XXX"></a>)
        $(temporaryString).find("a[name]").remove();
}

In the else statement (when the string is HTML), I’m trying to (unsuccessfully) remove all HTML anchors using the function above.

How do I manipulate the object as HTML through jQuery?

Update

On further inspection, I’ve realized the problem is different from what I initially thought.

My issue is I’m not able to manipulate the variable (temporaryString) as a jQuery object. For example, the following will not affect the html of the object:

$(temporaryString).find("div").remove();

So, in theory if I have the following:

temporaryString = "<span>Span Content</span><div>DIV Content</div>";
$(temporaryString).find("div").remove();

I would assume ‘temporaryString’ should now equal:

<span>Span Content</span>

since the div is removed.

Is my logic wrong? It doesn’t seem to be working.

  • 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-23T07:20:37+00:00Added an answer on May 23, 2026 at 7:20 am

    Here’s your problem: In Javascript, strings are immutable, that means that they can’t be changed. Unless you assign something different to the variable temporaryString, that variable isn’t going to change.

    When you run this code:

    temporaryString = "<span>Span Content</span><div>DIV Content</div>";
    $(temporaryString).find("div").remove();
    

    This is what happens:

    1. "<span>Span Content</span><div>DIV Content</div>" is assigned to temporaryString
    2. $(temporaryString) runs, parsing temporaryString and creating a corresponding array-like object (the jQuery object) of html elements and returns it. temporaryString is left unchanged.
    3. .find("div") runs, finds all div elements in the result of the above step and returns them. temporaryString is left unchanged.
    4. .remove() runs, removing the elements returned by the previous step from the jQuery object. temporaryString is left unchanged.
    5. The objects and elements created by $(temporaryString).find("div").remove() pass out of scope and are deleted by the garbage collector. temporaryString has still not been changed.

    In short, if you don’t do anything with the result of $(temporaryString).find("div").remove(), nothing happens.

    If you want temporaryString to become "<span>Span Content</span>", you need to assign the result of all the manipulations you’ve done to the jQuery object back into the temporaryString variable. The best way to do this is to create a div element, set it’s contents to temporaryString, remove the desired elements, and assign the new contents of the div element back into temporaryString like this:

    temporaryString = $("<div>").html(temporaryString).find("div").remove().end().html();
    

    For your original question, you can try this:

    for(i = 0; i < copyFromSchedule.length; i++) {
        temporaryString = $(this).attr("ows_"+copyFromSchedule[i]);
        if ($(temporaryString).html() == null)
            { /* Is not HTML... */ }
        else {
            // Is HTML, remove any anchors found in this string (<a name="XXX"></a>)
            temporaryString = $("<div>").html(temporaryString).find("a[name]").remove().end().html()
        }
    }
    

    Sorry for the long winded answer.

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

Sidebar

Related Questions

I have a an ajax call returning JSON to a loop to populate form
I want to make an AJAX call to an HTML-returning page, extract part of
I have this simple ajax call . It works fine in firefox/chrome, returning number
I'm doing an Ajax request in which I have the server returning well-formed HTML,
I am running ASP.NET MVC Beta. I have an AJAX call running through jQuery
I have this code that performs an ajax call and loads the results into
I have coded some JavaScript to perform an ajax call in an asp.net application.
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
As the title mentions, I have a timeout callback handler on an ajax call,
I am using asp.net MVC to develop an application that will have ajax interactions.

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.