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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:16:22+00:00 2026-05-15T10:16:22+00:00

Why doesn’t this work? What would be a plausible solution to get this effect?

  • 0

Why doesn’t this work? What would be a plausible solution to get this effect?

$(document).ready(function() {

  $('#myLink1').click(
    function() { 
      $('#myLink1').replaceWith('<a id="myLink2" href="#panel2">#panel2</a>');
    });

  $('#myLink2').click(
    function() { 
      $('#myLink2').replaceWith('<a id="myLink3" href="#panel3">#panel3</a>');
    });

});

I’m new to loops and how I’m supposed to add strings and variables.

$(document).ready(function() {
  var panelNum = 8;
  for (i=1;i<=panelNum;i++){
    $('#myLink'+i).click(function() { 
      $('#myLink'+i).replaceWith('<a id="myLink'+(i+1)+'" href="#panel'+(i+1)+'">#panel'+(i+1)+'</a>');
    });
  };
});
  • 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-15T10:16:23+00:00Added an answer on May 15, 2026 at 10:16 am

    The problem is myLink2 doesn’t exist until mylink is clicked. You have to add the mylink2 handler after it is created. Try the following:

    function add_replace_with(i){
     $('#myLink'+i).click(
        function() {
         do_replace_with(i)
              return false;
        });
    }
         function do_replace_with(i){
           $('#myLink'+i).replaceWith('<a id="myLink'+(i+1)+'" href="#panel'+(i+1)+'">#panel'+(i+1)+'</a>');
    
         $('#myLink'+(i+1)).click(
          function() {
            do_replace_with(i+1)
          });   
         }
    
    $(document).ready(function() {
     add_replace_with(1);
    });
    

    I should note, that you might be better of hard-coding the links and just using .show() to toggle them.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It could be useful if the size of the buffer… May 16, 2026 at 8:40 am
  • Editorial Team
    Editorial Team added an answer int is what is known as a primitive type. It… May 16, 2026 at 8:40 am
  • Editorial Team
    Editorial Team added an answer If a custom attribute is missing, it is not going… May 16, 2026 at 8:40 am

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

Doesn't matter what I do, I simply can't get this to play a sound
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
Doesn't work with other modules, but to give an example. I installed Text::CSV_XS with
Doesn't seem to work for me, maybe I just doing it wrong
Doesn't the space occupied by a variable get deallocated as soon as the control
Doesn't oEvent.preventDefault(); work in GC? I need to prevent selecting text when the onmove
Why doesn't this Google Chart API URL render both data sets on this XY
There doesn't seem to be much info on this topic so I'm going to
Why doesn't the designer work if you inherit from an own written genericform? Suppose
For some reason, after submitting a string like this Jack’s Spindle from a text

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.