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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:58:34+00:00 2026-06-08T23:58:34+00:00

The HTML I have is something like the following: <div id=container> <ul> <li> <div

  • 0

The HTML I have is something like the following:

<div id="container">
  <ul>
    <li>
        <div class="oneClass">
            <img src="http:image.jpg">
        </div>
        <div class="anotherClass" id="oneID">
            <div class="twoClass" id="randomID">
                <cite class="user">
                    <a href="http://someURL" >Name</a>
                </cite>
                <span class="icon user"></span>
                <span class="threeClass">
                    <a href="http:URL#oneID">some text</a>
                </span>
            </div>
            <p class="content" id="randomID">some words content</p>
        </div>
    </li>
    <li>
        <div class="oneClass">
            <img src="http:image.jpg">
        </div>
        <div class="anotherClass" id="anotherID">
            <div class="twoClass" id="randomID">
                <cite class="user">
                    <a href="http://someURL" >Name</a>
                </cite>
                <span class="icon user"></span>
                <span class="threeClass">
                    <a href="http:URL#anotherID">some text</a>
                </span>
            </div>
            <p class="content" id="randomID">some words content</p>
        </div>
    </li>
  </ul>
</div>  

What I need is to find a way to detect the next ID after oneClass and use to create another div around oneClass.
Example:

    <div id="container">
       <ul>
        <li> 
      <div id="myName_oneID">
            <div class="oneClass">
         <img src="http:image.jpg">
            </div>
      </div>
         <div class="anotherClass" id="oneID">
            <div class="twoClass" id="randomID">
                <cite class="user">
               <a href="http://someURL" >Name</a>
                 </cite>
                    <span class="threeClass">
                         <a href="http:URL#oneID">some text</a>
                    </span>
              </div>
                <p class="content" id="randomID">
                   some words content
                </p>
        </div>
     </li>
      <li>
        <div id="myName_anotherID">
             <div class="oneClass">
                <img src="http:image.jpg">
             </div>
         </div>
             <div class="anotherClass" id="anotherID">
                 <div class="twoClass" id="randomID">
                     <cite class="user">
                    <a href="http://someURL" >Name</a>
                      </cite>
                     <span class="threeClass">
                    <a href="http:URL#anotherID">some text</a>
                     </span>
                 </div>
             <p class="content" id="randomID">
                   some words content
             </p>
          </div>
     </li>
    </ul>
</div> 

I’ve tried to get it from the anchor like this:

    $(".threeClass a").map(function () {
    var myID ="myName_" + this.hash.replace(/#/, '');
    //alert(myID);
$(".oneClass").each(function () {
    $(this).wrap("<div id='" + myID + "' />");
});

});

If I test the alert(myID), it detects correctly but when I try use it to wrap a new div, it creates it with the same Id for all oneClass.

Can it be done?

I’m a newbie at javascript or Jquery and appreciatte the help or guidance on the right way.

Thank you.

  • 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-08T23:58:37+00:00Added an answer on June 8, 2026 at 11:58 pm

    Try this

    $('.oneClass').each(function(){
        id=$(this).next().attr('id');
        $(this).wrap('<div></div>').parent().attr('id', 'myName_'+id);
    });
    

    DEMO (See the source).

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

Sidebar

Related Questions

So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
So basically I have something like this <div class=iframe-holder> <span></span> <iframe src=iframe.html width=200 height=200
I have HTML something like the following: <div id=quoteContainer> <div class=quote prototype></div> <div class=quote
i have my html something like this... <div class = content> <div class =
If my HTML says something along the following <div class=container> <div class=element> </div> <div
I have something like following <a class=item href=a.htm> <div class=title>abcd</div> <div class=body>abcd</div> </a> with
I have HTML something like this: <table> <tr> <td><div class='record'>Record Link</div></td> <td><div class='delete' style='display:none;'>Delete
I have a set up of the following HTML <div class=container> <div class=box>Content</div> <div
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I have JSON like this: { something: http://something.com } and HTML like this: <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.