Calling function from another javascript inside jquery -


i have javascript file named loader.js contains function called initialize(). want call function via jquery. html file:

<!doctype html>      <html>          <head>          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>          <script src="loader.js" ></script>      	 <script type="text/javascript">      	 jquery(document).ready(function() {      	 jquery(document).on("click", ".link", function(e) {              e.preventdefault();      		var a= $(this).text();      		 window.initialize= function{      		 };      		initialize(a);      		      		       		 });      		 });      	                  	      	</script>          </head>          <body >      	<h1>welcome website </h1>      	<a href="#" class="link"> link1 </a>      	<a href="#" class="link"> link2 </a>          <div id="main">      	      	</div>          </body>      </html>

this loader.js:

 function initialize(a) {     $('#main').html= a;          } 

i not know wrong script, have debug jquery working fine funtion not working correctly.
want whenever function clicked again div should refreshed example first contain link1 when link2 clicked link1 should removed inside div how can accomplish task????

thanks in advance

you're not including loader script. add <script src='loader.js'></script> before jquery code.

the code in loader.js should inside jquery(document).ready callback since it's using jquery (the html method).

also @jiihoo pointed out should use $('#main').html(a); instead of $('#main').html = a;.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -