Jump to content

Replacing Values on document tags


inktherapy

Recommended Posts

Hi,I am writing a code for my news article (just one of my exercises in Javascript). I need to have a link that will display "read more" in html e.g. <div><a href="www.w3shools.com">read more</a></div> and then I want to replace the value "read more" to its source link which is "www.w3schools.com" by triggering a button, this will now display <div><a href="www.w3schools.com">www.w3schools.com</a></div> in html. I have a sample code below(please check), but the problem is, if I have many articles that I want to process the same result as I mentioned above, how will I do it? What I am thinking now is writing the same pattern of codes but this will be much harder than manually copy and paste the source link to replace the read more.Help! Thanks.

<html><head><script type="text/javascript">function getLink() {x = document.getElementsByTagName('a');document.getElementById('one').innerHTML=x[0];}</script></head><body><div>Man Killed by a killer mouse!</div><div id="one"><a href="http://www.w3schools.com" name="one">read more</a></div><button onclick="getLink()">Get now!</button></body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...