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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:22:42+00:00 2026-06-08T03:22:42+00:00

In this fiddle buttons are appended to dynamically within a loop. How can the

  • 0

In this fiddle buttons are appended to dynamically within a loop. How can the code be updated so that that each button is added just once in the loop instead of multiple times ? I think this is because of the clone method ?

http://jsfiddle.net/8JXTT/9/

Fiddle code :

<div data-role="page" id="firstpage">

        <div data-role="header">
                <h1>First Page</h1>
        </div>

<div data-role="content" id="links">
        <a href="#secondpage" data-role="button">Link button</a>
</div>

        <div data-role="footer">
                <h4>Page Footer</h4>
        </div>

</div>

<div data-role="page" id="secondpage">

        <div data-role="header">
                <a href='#' class='ui-btn-left' data-icon='arrow-l' onclick="history.back(); return false">Back</a><h1>Bar</h1><a href="#firstpage">home</a>
        </div>

        <div data-role="content">
                <p>I'm first in the source order so I'm shown as the page. (this is secondpage)</p>
                <p><a href="#thirdpage">Go to third page</a></p>
        </div>

        <div data-role="footer">
                <h4>Page Footer</h4>
        </div>
</div>
​
$(document).ready(function() {

    for (var i = 0; i < 4; i++) {
    var linkButton = $('#links a').clone(true);
    linkButton.find('span.ui-btn-text').text('Link Button2');
    $('#links').append(linkButton);
}

});​
  • 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-08T03:22:45+00:00Added an answer on June 8, 2026 at 3:22 am
    $(document).ready(function() {
        for (var i = 0; i < 4; i++) {
          var linkButton = $('#links a:first').clone(true); // clone first one only
          linkButton.find('span.ui-btn-text').text('Link Button2');
          $('#links').append(linkButton);
        }
    });​
    

    Demo

    OR

    $(document).ready(function() {
        var linkButton = $('#links a').clone(true); // keep reference outside of loop
        for (var i = 0; i < 4; i++) {
          linkButton.find('span.ui-btn-text').text('Link Button2');
          $('#links').append(linkButton.clone(true));
        }
    });
    

    Demo

    In your code clone() method make copy of all a tag exists in the #links in each turn.

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

Sidebar

Related Questions

fiddle code: <button onclick=this.disabled=true; setTimeout(function(){this.disabled=false;},500);>click</button> this seems to refer to the window rather than
In this fiddle http://jsfiddle.net/dAHqe/2/ I've created examples for the 2 main uses (that I've
In this fiddle I'm just trying to return true : http://jsfiddle.net/WCFtp/ for jQuery key
Referencing this Fiddle ( http://jsfiddle.net/j5uGN ), how can I toggle a clicked image's border
I have this fiddle : http://jsfiddle.net/XjeCf/1/ that works like I want and this one
look at this fiddle: http://jsfiddle.net/ugxNK/ I want that the first list element is in
I have multiple table rows that has a set of radio buttons on each
Regarding the code here : The radio buttons in the fiddle aren't acting the
In this fiddle I would like the Delete and Update buttons to appear in
In this fiddle http://jsfiddle.net/5L8Q8/28/ , if you click the black button, it randomly selects

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.