I'm trying to load a javascript script link in div/span.(Script contains some image and link) script must come inside span when I run the page.
I have tried with load(),$.getscript but unfortunately I was unable to do so.My script must run as soon as document load without any click or any 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 this 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";
// Use any selector
$(".loader").append(s);
});
</script>
</head>
<body>
<span class="loader">
</span>
</body>
</html>
Any help will be helpful.