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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:05:56+00:00 2026-06-12T23:05:56+00:00

I have an ajax response which looks like this: <div class = element3> some

  • 0

I have an ajax response which looks like this:

<div class = "element3"> some other text</div>

and I want to replace element1 in the following with resp:

<div class = "a">
  <div class = "element1"></div>
  <div class = "element2"></div>
</div>

So after the replace I would get:

<div class = "a">
  <div class = "element3"> some other text</div>
  <div class = "element2"></div>
</div>

I tried replaceChild() but it does not work because the response is not a DOM object..

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-12T23:05:57+00:00Added an answer on June 12, 2026 at 11:05 pm

    Unlike innerHTML() which only replaces the content between the tags, outerHTML() will allow you to replace the opening & closing tags as well, effectively replacing the DOM node.

    var element = document.getElementsByClassName('element1')[0];
    element.outerHTML("<div class = 'element3'> some other text</div>");
    

    See:

    • http://help.dottoro.com/ljloliex.php
    • http://help.dottoro.com/ljdkwhqf.php

    Note: Due to the use of getElementsByClassName(), this solution is valid for (see: http://caniuse.com/getelementsbyclassname):

    • Internet Explorer 9+
    • Firefox 3+
    • Opera 9.5+
    • Chrome 4+
    • Safari 3.1+
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have an ajax function which looks like this (basically, it's simplified): function getPage(targetURL,
I have my own edit in place function for jquery which looks like this
I have a form which is loaded from ajax response that contains some textarea
I have a php function which returns JSON in response to a ajax request
I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
I have AJAX requests from which I get a JSON-format response, which is being
I have a AJAX requests which returns a string of XML which I'd like
Have an ajax call to updateUser which does this: puts session[:user_id] user = User.find(params[:user_id])
I have followed this tutorial which uses jQuery UI to generate Facebook tokens like:

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.