javascript - Rails + JQuery: Getting to a sibling div from script -
i have rails partial renders html:
<div class="content"></div> <script> // load content here , adjacent div , populate it. </script>
this partial template gets embedded in main document server , several times response ajax requests. page has several instances of partial.
whenever script executes want div adjacent script affected.
so hoping if script, can div. use jquery , use several async scripts (this prevents me using last executed script)
i adjacent div through document.currentscript
, problem browsers don't support it.
then, way create sort of uuid id div , access id dom?
i wished div supported onload, sadly not.
you can create element after <script>
(document.write
) , find .content
relative it.
(function(){ var id = 'id' + (new date().gettime()); document.write('<div id="'+id+'"></div>'); var elem = document.getelementbyid(id); var content = elem.previouselementsibling.previouselementsibling; content.innerhtml = 'new content'; })();
Comments
Post a Comment