title: How to set id of next element into href attribute of link using jquery?
body: <p>I have to assign to many html <code>href</code> attributes (a tag) the value of their respective id immediately following.
  With my code, I just get a only value (the first).
  Thanks so much.
  Juri</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".anchor").attr("href","#"+($(".anchor").closest("div").next("div").attr("id")));</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;div&gt;
      &lt;a class="anchor"&gt;Get anchor 1&lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="link1"&gt;
      &lt;p&gt;A paragraph&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;a class="anchor"&gt;Get anchor 2&lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="link2"&gt;
      &lt;p&gt;Another paragraph&lt;/p&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>