0

I'll illustrate with an example: I need to convert the following html with javascript

<a href="aaa.kmz"></a>
<a href="eee.kmz"></a>
<a href="rrr.kmz"></a>
...

to code where all href values has changed only the last letter

<a href="aaa.kml"></a>
<a href="eee.kml"></a>
<a href="rrr.kml"></a>
...
2
  • 4
    What have you tried? & Writing the perfect question Commented May 18, 2012 at 14:52
  • I know how to retrieve a value of attribute and obviously it's simple to add something to this value but in this case I need to 'go inside'. Commented May 18, 2012 at 14:59

1 Answer 1

4

Get the a tags, loop through them and replace .kmz with .kml:

​var tags = document.getElementsByTagName("a");

for(var i = 0, l = tags.length; i < l; i++) {
    tags[i].href = tags[i].href.replace('.kmz', '.kml');
}​​​​

Working Example - http://jsfiddle.net/Ln4s4/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.