Skip to main content
2 of 5
deleted 8 characters in body; edited title
konijn
  • 33.8k
  • 5
  • 69
  • 264

Dynamically generating anchors

description::
This function creates a series of links at a desired destination
by the usage of premade tag system.

usage:::
createMyTAGS_DATA
pass in a single line all the links as: LinkText;LinkAddress;;
createMyTAGS_LOCATION
pass the destination id of a div,span to render the result.

Result would be::
<a href="LindAddress1">LinkText1</a><a href="LindAddress2">LinkText2</a> [...]

Note::
each of tag(LinkText;LinkAddress;;) must have more the 10 characteres.

<span onclick="createMyTAGS('LinkText1;LinkAddress1;;LinkText2;LinkAddress2;;','renderHERE');" style="cursor:pointer;"><b>click here</b></span>

<div id="renderHERE"></div>

<script>
    function createMyTAGS(createMyTAGS_DATA,createMyTAGS_LOCATION){
    try{ var linkTags = createMyTAGS_DATA;
         var v1 = createMyTAGS_LOCATION;
    while (linkTags !== '' && linkTags.indexOf(";;") > 10){
    var linkNew = linkTags.slice(0, linkTags.indexOf(";;"));
    var linkText = linkNew.slice(0, linkNew.indexOf(";"));
    linkTags = linkTags.replace(linkNew+';;', '');
    linkNew = linkNew.replace(linkText+';', '');
    linkNew = '<a href="'+linkNew+'" title="'+linkNew+'" target="_blank">'+
              linkText+'</a> ';
    document.getElementById(v1).innerHTML = 
    document.getElementById(v1).innerHTML + linkNew;
    }
    }catch(err){alert('createMyTAGS: '+err.message+
    '; - statement('+createMyTAGS_DATA+','+createMyTAGS_LOCATION+')')}
    }
</script>

Nickname
  • 47
  • 1
  • 1
  • 6