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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:43:26+00:00 2026-06-14T22:43:26+00:00

I am trying to traverse a dynamically generated page, grabbing specific span ID an

  • 0

I am trying to traverse a dynamically generated page, grabbing specific span ID an then append that id inside an href to the previous span. Currently this generates BOTH links inside each h2.classA instead of the respective single link in each instance. Should I be assigning the each() to the h2 instead? Any help is greatly appreciated.

Existing HTML

    <h2>
    <span class="classA"> </span> 
    <span class="classB" id="somename"> SomeName </span>
    </h2>

    <h2>
    <span class="classA"> </span> 
    <span class="classB" id="anothername"> SomeName </span>
    </h2>

Attempt:

    $("h2 span.classB").each(function() {
    var content = $(this).attr('id');

    $('h2 span.classA').append('<a href="index.php?title='+content+'"> edit me </a>');              
    });

Desired HTML result

    <h2>
    <span class="classA"><a href="index.php?title='+somename+'"> LINK1 </a></span> 
    <span class="classB" id="somename"> SomeName </span>
    </h2>

    <h2>
    <span class="classA"><a href="index.php?title='+anothername+'"> LINK2 </a></span> 
    <span class="classB" id="anothername"> AnotherName </span>
    </h2>
  • 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-14T22:43:28+00:00Added an answer on June 14, 2026 at 10:43 pm

    You are appending the anchors to all the classA elements in each iteration, for selecting the previous span element, you can use the prev method:

    $("h2 span.classB").each(function() {
        $(this).prev().append('<a href="index.php?title='+this.id+'"> edit me</a>');              
    });
    

    http://jsfiddle.net/c7V9z/

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

Sidebar

Related Questions

I'm trying to traverse an AJAX response, which contains a remote web page (an
I am working on a page that uses XPATH to traverse an XML document
I'm trying to traverse a ul that has been appended to before traversing like
I'm trying to write code that will traverse an undirected, unweighted graph. Essentially, the
I'm trying to write a function that will traverse the file directory and give
I'm trying to insert some dynamically generated html (via PHP) into a table, but
Here's books.xml , an xml that I'm trying to traverse: <?xml version=1.0 encoding=ISO-8859-1?> <!--
I am trying to traverse and find links with a specific extension (*.ashx) so
i am trying to traverse a given directory and create a list of files
I'm a newbie to selenium. I'm trying to traverse all the elements in a

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.