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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:33:14+00:00 2026-06-12T01:33:14+00:00

Before you mark this as a duplicate of JQuery: elegant way to replace set

  • 0

Before you mark this as a duplicate of JQuery: elegant way to replace set of elements with another set, please read my question.

The answers of the question which I mentioned above only allow the replacing of all the elements inside a certain parent selector with another set.

What I want is to replace a certain set, like for example #foo1 and #foo3 in the following example, but not #foo2 and #foo4:

<div id="main">
  <div id="foo1">Foo1</div>
  <div id="foo2">Foo2</div>
  <div id="foo3">Foo3</div>
  <div id="foo4">Foo4</div>
</div>

Just say I wanted to replace the elements #foo1 and #foo3 with two divs with an id of #foo5 and #foo6. I don’t want to change any other elements.

Would this be remotely possible? If so, how?

  • 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-12T01:33:15+00:00Added an answer on June 12, 2026 at 1:33 am

    You can use replaceWith method.

    $('#foo1').replaceWith($('#foo5'))​
    

    Or:

    $('#foo1').replaceWith('<div id="foo5">Content</div>')​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please read this entire question before you try to mark this as too controversial.
Edit: Thanks for the quick answers. Please mark this question for deletion. It doesn't
Okay..so before you mark this is as a repeated question, read it. I've implemented
Before you mark this as answered in another post (I already saw those). But
Before you mark this as a duplicate of this post, know that I am
Possible Duplicate: What does the exclamation mark do before the function? What's the point
before I start I want to point out that I tagged this question as
Possible Duplicate: What does the exclamation mark do before the function? If you look
Possible Duplicate: What does the exclamation mark do before the function? I saw a
I think this has happened to me before. This is A3.txt : %INSERT MARK

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.