Can I concatenate two strings in HTML?
I want to achieve the following functionality-
<a href="#"+"javascript:document.getElementsByTagName('div')[0].id">go to the 1st DIV tag.</a> It could have been done using document.write() in javascript but I want to know if there is any concatenation functionality in HTML itself.
6 Answers
No, there isn't. HTML is markup, it is not turing complete.
One (primitive) way to achieve this with JavaScript would be
<a href="#" onclick="window.location.hash='#'+document.getElementsByTagName('div')[0].id; return false;"> go to the 1st DIV tag. </a> But since those links are useless when JS is not available, they should probably only be generated by JS in the first place.
1No, there isn't. HTML is markup. You should use dynamic HTML and JavaScript to achieve this.
you can do this by using this.href in java script
<a href="#" onload="this.href=this.href+document.getElementsByTagName('div')[0].id;" > ex
<a href="targetWithInDoc.html" onload="this.href=this.href+'#block1';" >block 1</a> 1This can't be done in the way you're attempting, but if JavaScript is running on the client anyway then you can still achieve the functionality you're looking for. You just need to separate the tag from the script:
<a href="#">Go to the first DIV tag</a> <script type="text/javascript"> document.getElementById('someID').href = '#' + document.getElementsByTagName('div')[0].id; </script> I know it wont help u now but I'm posting this for others who will come to this question by searching
we can achieve it this way :
<a href='<%#String.Concat("string1", "string2")%>'></a>