Using JavaScript To Change the HTML Contained In An External Script -
i have element on website hosted externally , referenced in script on page.
i want automatically change text within content displays tomorrow's date.
script widget:
<script src="//my.externalwidget.com/12345.js" type="text/javascript" charset="utf-8" async="async"></script>
html contained in external script:
<div id="changeheaderone">this should display tomorrow's date</div>
my js:
<script type="text/javascript"> var currentdate = new date(new date().gettime() + 24 * 60 * 60 * 1000); var dateparse = currentdate.tostring(); var dayabbr = dateparse.substr(0, 3); var day = currentdate.getdate(); var month = currentdate.getmonth() + 1; var year = currentdate.getfullyear(); document.getelementbyid("changeheadertwo").innerhtml = "tomorrow's date " + dayabbr + " " + month + "/" + day + "/" + year; document.getelementbyid("changeheaderone").innerhtml = "tomorrow's date " + dayabbr + " " + month + "/" + day + "/" + year;
i know script working because runs on #changeheadertwo (located in dom) not on #changeheaderone (externally hosted , loaded using script on top).
any ideas how make apply externally loaded code well?
you using document.getelementbyclass()
(which should document.getelementsbyclassname()
) when div has id. use document.getelementbyid()
instead.
Comments
Post a Comment