massive or auto anchor tag

Status
Not open for further replies.

flaiho

Active Member
354
2013
57
645
im doing some index and tuturial on html


i know the code.

Code:
<a href="1. Intruduction">1. Intruduction</a>
<a href="2. Html>2. Html</a>
<a href="3. Anchor tag">3. Anchor tag</a>

<a name="1. Intruduction"1. Intruduction</a>
<a name="2. Html"2. Html</a>
<a name="3. Anchor tag"3. Anchor tag</a>


but i wanna know if theres a faster way to add it and not one by one
 
3 comments
Telling us where the links and names came from would be helpful.But yes you can use javascript to read an array or list of the information and dynamically build that code for you based on the input...
 
Last edited:
the name could be different but always start with numbers so the output always can be
<a href="#2>

<a name="2</a>


but the problem is how to do it :p (for me of course)
 
Code:
<script type="text/javascript">
var array = ["link1","link2","link3","link4"];
var c = 0;
for (var i in array)
{
c++; document.write("<a href='#"+c+"'>"+array[i]+"</a><br>");
}
</script>

Just add the above code where you want the links to be written. If you do not want a <br> remove it. Also you can add or remove whatever you want in the array.
 
Last edited:
Status
Not open for further replies.
Back
Top