Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript array of hrefs
    text
    copied!<p>I am trying to create an array with different hrefs to then attach to 5 separate elements.</p> <p>This is my code:</p> <pre><code>var link = new Array('link1', 'link2', 'link3', 'link4', 'link5'); $(document.createElement("li")) .attr('class',options.numericId + (i+1)) .html('&lt;a rel='+ i +' href=\"page.php# + 'link'\"&gt;'+ '&lt;/a&gt;') .appendTo($("."+ options.numericId)) </code></pre> <p>As you can see I am trying to append these items from the array to the end of my page so each link will take the user to a different section of the page. But i have not been able to do this. Is there a way to to create elements with different links?</p> <p>I am new to javascript so I am sorry if this doesn't make a whole lot of sense. If anyone is confused by what i am asking here I can try to clarify if I get some feedback.</p> <p>The code I would Like output is:</p> <pre><code> &lt;ul class="controls"&gt; &lt;li class="controls1"&gt;&lt;a href="page.php#link1"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="controls2"&gt;&lt;a href="page.php#link2"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="controls3"&gt;&lt;a href="page.php#link3"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="controls4"&gt;&lt;a href="page.php#link4"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="controls5"&gt;&lt;a href="page.php#link5"&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Which is similar to what I am getting, however when I apply the fix that andres descalzo has supplied, my list elements are each repeating themselves 5 times.</p> <p>Any solutions would be greatly appreciated.</p> <p>Thanks,</p> <p>jason</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload