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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:21:14+00:00 2026-06-01T20:21:14+00:00

I’m having some trouble with what I thought would be a simple problem. I’d

  • 0

I’m having some trouble with what I thought would be a simple problem.

I’d like to automate the creation of anchor links for a series of blog posts – I’ve been trying to use the each() command to loop through children in the parent div but I just can’t get it working properly and am now so confused I don’t know what I’m doing. ((@_@))

The blog content is structured like so:

<div id="content">
 <div class="list-journal-entry-wrapper">
  <div class="post-text">
    <div id="item101" class="journal-entry">...</div>
   </div><div class="post-text">
    <div id="item102" class="journal-entry">...</div>
   </div><div class="post-text">
    <div id="item103" class="journal-entry">...</div>
   </div>
  </div>
 </div>
</div>

What I want to do is use the unique item number (id="item101") for each .journal-entry post to create a list of anchor links, like this:

<div id="news-links">
  <a href="#item101">Post 101</a><br/>
  <a href="#item102">Post 102</a><br/>
  <a href="#item103">Post 103</a><br/>
</div>

I’m having trouble finding the id="xxxxx" for each post:

Once I have that id, it should be pretty simple to write out anchor links using the id value as the href

<a href="#xxxxx">Post xxxxx</a>

I’d really appreciate an example so I can get my head around the each() command.

Or is there a better way to do this?


Solved! Thanks to examples from adeneo and theCodeParadox, I managed to learn a few things in the process and took a little from both solutions – in the interest of assisting others, here is my final completed solution as was used for my specific application:

http://jsfiddle.net/mDSWE/3/

Note there are additional divs in the actual HTML and the final jQuery routine looks for the article title h2.title to use as the link text and then using the parents() function, finds the id attribute of the first wrapper div id="item12345" which it uses for the anchor links href.

$('h2.title a').each(function() {
   var el = $(this);
    var id = el.parents('div.journal-entry:first').attr('id');
   var insert = '<a href="#' + id + '">' + el.text() + '</a></br>';
   $('#news-anchors').append(insert);
});

Working beautifully, so thank you for taking the time to help me out.

  • 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-01T20:21:15+00:00Added an answer on June 1, 2026 at 8:21 pm
    var newsLinks = '<div id="news-links">';
    
    $(".journal-entry").each(function(index, item) {
        newsLinks += '<a href="#'+item.id+'">Post '+item.id.replace('item', '')+'</a><br/>';
    });
    
    newsLinks += '</div>';
    

    FIDDLE

    It can also be done like so:

    var newsLinks = '<div id="news-links">';
    
    $.each($(".journal-entry"), function() {
        newsLinks += '<a href="#'+this.id+'">Post '+this.id.replace('item', '')+'</a><br/>';
    });
    
    newsLinks += '</div>';
    

    FIDDLE

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping 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.