Loading javascript in Span/Div in jquery -



Loading javascript in Span/Div in jquery -

i'm trying load javascript script link in div/span.(script contains image , link) script must come within span when run page.

i have tried load(),$.getscript unfortunately unable so.my script must run document load without click or user action.

html

<span class=" loader"></span>

jquery:

<script type="text/javascript"> $.ajax({ type: "get", url: "test.js", datatype: "script" success: function( strhtml ){ $( ".loader" ).html( strhtml ); }); </script>

i tried also:

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>home</title> <script src="https://code.jquery.com/jquery-1.11.1.js" type="text/javascript"></script> <style> </style> <script> $(document).ready(function() { var s = document.createelement("script"); s.type = "text/javascript"; s.src = "test.js"; // utilize selector $(".loader").append(s); }); </script> </head> <body> <span class="loader"> </span> </body> </html>

any help helpful.

this may not right approach, tried below , working me...

$(document).ready(function() { var s = document.createelement("script"); s.type = "text/javascript"; s.src = "http://scriptlocation/test.js"; // utilize selector $(".loader").append(s); });

can please refer below link, might helpful ajax/jquery - load webpage content div on page load?

javascript jquery html ajax

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -