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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:59:07+00:00 2026-05-16T13:59:07+00:00

<div id=’one’ class=’foo’>Hello</div> $(‘#one’).replaceWith(<div id=’one’>World</div>) Above code is producing <div id=’one’ class=’foo’>World</div> However the

  • 0
<div id='one' class='foo'>Hello</div>

$('#one').replaceWith("<div id='one'>World</div>")

Above code is producing

<div id='one' class='foo'>World</div>

However the desired output is

<div id='one'>World</div>

Notice that replaceWith is changing the content inside the div but not the attributes of the div itself.

  • 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-16T13:59:08+00:00Added an answer on May 16, 2026 at 1:59 pm

    As with the others that have commented on this, I can not reproduce the problem.

    $(document).ready(function(){
    
      $('div').live('click', function(){
    
        $('#one').replaceWith('<div id="one">World</div>');
    
      });
    
    });​
    

    That causes

    <div id='one' class='foo'>Hello</div> 
    

    this to change to:

    <div id='one'>World</div>
    

    However, alternatively you could use this:

    $(document).ready(function(){
    
      $('div').live('click', function(){
    
        $('#one').removeAttr('class').html('World');
    
      });
    
    });​
    

    Mind you those are on click, you could remove the click and do it however you like.

    See here:
    http://jsbin.com/adesi3/edit

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

Sidebar

Ask A Question

Stats

  • Questions 517k
  • Answers 517k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll need to run PSFTP as a subprocess and speak… May 16, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer As you already noticed, jQuery adds a style attribute to… May 16, 2026 at 7:49 pm
  • Editorial Team
    Editorial Team added an answer When you use //title this searches for all <title> elements… May 16, 2026 at 7:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Div box dimensions are measured using jQuery with following code: $(document).ready(function(){ var h =
#div that holds table, table tr td.class of td now what goes here to
Lots of div and classes name are being used in the code. http://www.csszengarden.com/ Is
I have a div with the following CSS class defined: <div class=ui-button ui-state-active>bla bla
I have a nested div like this <div id=one> <div id=two> id two goes
Basically, what I'm trying to create is a page of div tags, each has
div#thing { position: absolute; top: 0px; z-index: 2; margin: 0 auto; } <div id=thing>
DIV behave like an IFRAME & load url using ajax for a web application
#div p { color: red !important; } ... #div p { color: blue; }
I want a div's width and height to change with the browser as the

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.