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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:26:10+00:00 2026-05-31T10:26:10+00:00

This is my input i have like 120 lines of code like this one

  • 0

This is my input i have like 120 lines of code like this one and the city names are not limited, there are 20 cities at this moment but it might go up like 40 or even 60.

<a href="somelink" rel="city3">Name1</a><br>
<a href="somelink" rel="city2">Name2</a><br>
<a href="somelink" rel="city1">Name4</a><br>
<a href="somelink" rel="city4">Name6</a><br>
<a href="somelink" rel="city3">Name5</a><br>
<a href="somelink" rel="city1">Name3</a><br>
<a href="somelink" rel="city4">Name7</a><br>
<a href="somelink" rel="city1">Name8</a><br>

and i need this output to group them and give a title named the city they belong

<h1>city1</h1>
<div class="gather">
<a href="somelink" rel="city1">Name4</a><br>
<a href="somelink" rel="city1">Name3</a><br>
<a href="somelink" rel="city1">Name8</a><br>
</div>
<h1>city2</h1>
<div class="gather">
<a href="somelink" rel="city2">Name2</a><br>
</div>
<h1>city3</h1>
<div class="gather">
<a href="somelink" rel="city3">Name1</a><br>
<a href="somelink" rel="city3">Name5</a><br>
</div>
<h1>city4</h1>
<div class="gather">
<a href="somelink" rel="city4">Name6</a><br>
<a href="somelink" rel="city4">Name7</a><br>
</div>

i believe wrapper is the thing im looking for

  • 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-31T10:26:11+00:00Added an answer on May 31, 2026 at 10:26 am

    You can select each of the sets of elements by their rel attribute, then append them into another structure. If you .append() an element somewhere that already exists in the DOM, it will be moved:

    $(function () {
    
        //get all the links that have a `rel` attribute that starts with `city`
        var $links = $('#container').children('a[rel^="city"]'),
    
            //setup an output variable to sort the links
            output = {};
    
        //iterate through each of the links and add them to an object sorted by `rel` attribute
        $.each($links, function (index, element) {
    
            //get the number after `city` in the `rel` attribute
            var cityNumber = $(element).attr('rel').substr(4);
    
            //if this index does not exist, make it
            if (typeof output[cityNumber] == 'undefined') {
                output[cityNumber] = [];
            }
    
            //push element into proper index
            output[cityNumber].push(element);
        });
    
        //remove the container's HTML
        $('#container').empty();
    
        //loop through the `output` object
        $.each(output, function (index, obj) {
    
            //append a new set of links for each index (sorted by `rel` attribute)
            $('#container').append('<h1>city' + index + '</h1>').append($('<div />', { class : 'gather' }).append(obj));
        });
    });​
    

    Here is a demo: http://jsfiddle.net/d2FKS/1/

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

Sidebar

Related Questions

I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
So basically, I have something like this - Input file with 2 integers. Code,
If I have code like this: <form id=test_form> <input type=text value=Original value /> </form>
I have some input like this: aaaaa bbb \n cccccc\n ddddd \neeee And I
For example I have a css style like this : input.validation-passed {border: 1px solid
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I have an input control on a page like this: <input type=button causesvalidation=false runat=server
i have done something like this: <form action=validate.php method=get> Id :<input type=text name=pID/><br/><br/> Name
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;

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.