jquery - How can I add javascript to the head of an html document to listen for a click on an element not yet added to the DOM? -
jquery - How can I add javascript to the head of an html document to listen for a click on an element not yet added to the DOM? -
i using 3rd party web app allows place own code in head of html page. rest of document auto-generated place can insert custom code in head before added dom.
i trying add together click events various buttons loaded in dom. want browser window resize depending on id of button clicked.
i tried this:
<script type="text/javascript"> window.onload=function(){ document.getelementbyid("resize").onclick = window.resizeto(250, 250); }; </script>
because hoping if used onload event add together onclick event wait until loaded , wouldn't null reference error. don't null reference error, onclick doesn't work.
i tried utilize jquery because 1 post read suggested listening click events , checking id of element triggered event, not sure if using correctly. first time i've ever used jquery. didn't work either.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).click(function() { if(event.target.id == 'resize') { window.resizeto(250,250); }; }; </script>
the real reply may isn't possible, hoping there solution haven't been able find online.
to summarize, there way resize browser window based on id of element clicked within of 3rd party web app? script has in head of document before elements added dom.
thank help.
you can set code in document.ready
, delegate element may added in future. see http://api.jquery.com/on/ more details.
$(document).on("click", "selector of element added in future", function(){ //execute code });
javascript jquery html dom
Comments
Post a Comment