user3285762
user3285762

Reputation: 1

Is it possible to edit html generated by javascript with more javascript?

I need to use a javascript file that is server generated and which creates some html. But I am not happy with the html it creates. I fixed most of this in CSS, but the last problem is that the hrefs point to the wrong place. Is there any way to change these hrefs? I tried putting some scripting after the original call, but it did not work:

<script type="text/javascript" src="http://widget.seekandfind.com/publications?id=dd15fc98d1a83f5e1bcecf3f378a1269c00de96f"></script>
<script type="text/javascript">
var element = document.getElementsByClassName('saf-links')[1].getElementsByTagName('a')[0];
element.setAttribute("href","index.htm");
</script>

Thank you for any suggestions.

Upvotes: 0

Views: 53

Answers (1)

williambq
williambq

Reputation: 1125

It is most likely your JS is firing before the other JS has fully written to the DOM.

You probably need to use a listener (like using the jQuery doTimeout plugin with a loop, or if you are not using jQuery, making your own with a setTimeout() closure/loop) that waits until the HTML elements are ready to be addressed.

Test for an element you know should exist from the called script result and then proceed to modify it once it is available.

Upvotes: 1

Related Questions