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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:15:00+00:00 2026-06-03T05:15:00+00:00

Two h3 elements are selected with the following selector: $(#content div div ul h3).css(border,1px

  • 0

Two h3 elements are selected with the following selector:

$("#content div div ul h3").css("border","1px solid red");

I need to replace those elements as follows:

$('#content div div ul h3:eq(0)').replaceWith('<div>Top 5 Photos </div>');      
$('#content div div ul h3:eq(1)').replaceWith('<div>Recent Photos</div>');      

The problem I am having is that both elements ( eq(0) AND eq(1) ) are getting replaced with “Top 5 Photos”, and I cannot figure out why and how to fix this.

I will greatly appreciate any help with fixing this problem.

  • 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-03T05:15:01+00:00Added an answer on June 3, 2026 at 5:15 am

    try this:

    $('#content div div ul h3:eq(0)').replaceWith('<div>Top 5 Photos </div>');      
    $('#content div div ul h3:eq(0)').replaceWith('<div>Recent Photos</div>');    
    

    This answer seems to hazard, but it is right I think, because, when you first replace the h3 with div then the second h3 becomes first i.e eq(0). So you can’t never get a h3 with index 2 i.e eq(2).

    DEMO

    You can also try this:

    var replaces = ['<div>FIRET</div>', '<div>SECOND</div>'];
    $('#content div div ul h3').each(function(index, val) {
        $(this).replaceWith(replaces[index]);
    });
    

    DEMO

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

Sidebar

Related Questions

Two inline-block elements next to each other. .e{border:1px #ccc solid} .e:hover{border-color:#555} What I'd like
I'm looking for a nice way to mark/select all elements between two selected elements.
For example: You have this: <ul> <li>zero</li> <li>one</li> <li class=selected>two</li> <li>three</li> <li>more elements</li> </ul>
if i have a form with the following two elements. <select name= size=5 id=reasons
I need to fetch a node set containing elements that refer to exactly two
I have two elements: <input a> <input b onclick=...> When b is clicked, I
Exception: Failed to compare two elements in the array. private void assignNames(DropDownList ddl, Hashtable
I have two elements (a button and an anchor tag) both with a dynamical
When data binding two elements together, how can I include the binding information AND
How to write two span tags or two elements inside an cake php link

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.