I searched through internet and this site as well but haven’t found the answer. I would like to run a javascript code, which will go through articles at my site and choose&print some of them. The script works well when I run it after this articles:
[articles about smartphones]
[script which displays (prints) some of the articles about smartphones]
Obviously, it works correctly because script have what to search through – articles have already appeared at site, so javascript can take some elements.
But I want to invert the order:
[display some of the articles about smartphones there]
[show articles about smartphones there]
I assume that I should run the script after the articles loaded and than change the position of element, which was printed by script. I can do that with position: absolute; but it doesn’t look too elegant for me and I hope that there is another way to solve my problem. I tried body onload and running function at another place, but I haven’t do the trick.
Thank you for any help and suggestions : )
I suppose you are using document.write to generate the HTML code to redisplay some of the articles. You should not use document.write. Instead, put the script at very end of your document, to make sure all HTML elememts are already present in the DOM. Then create a new HTMLNode, eg a div, and put it where you want it or select one from the DOM and put your new HTML into that node (the simplest way is to set
innerHTML). Eg:This is very basic Javascript knowledge however. You should really read a good tutorial or a book on Javascript and DOM programming.