Is it possible to use Jquery to detect next id or anchor and use it to create a new div around another element?
<p>The HTML I have is something like the following:</p>

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

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

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

<p>I've tried to get it from the anchor like this:</p>

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

});
</code></pre>

<p>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.</p>

<p>Can it be done? </p>

<p>I'm a newbie at javascript or Jquery and appreciatte the help or guidance on the right way.</p>

<p>Thank you.</p>
