-1

I have a js file and execute with :

<div id="result">
    <script type="text/javascript" src="js/tracking.js"></script>
</div>

My main page has 2 divs (2 colums in page) and there are buttons on the left div. When i click to the first button, i would like to execute js file and display on the right. I can easily handle html files by :

$("#result").load( "test.html" );

But for js files i think i need to use getscript. I gave a shot with :

$("#result").load("#result",function(){$.getScript("js/tracking.js"); });

Ok, it executes the script but not loading into "result" div. It opens a new page and displays the result.

How should i modify?

Opti
  • 21
  • 3

1 Answers1

-1

As far as I can understand, you want to load, execute & display js file.

check this [demo][1]

  [1]: http://codepen.io/anon/pen/WrYQLX
Arun Sharma
  • 1,331
  • 8
  • 11
  • Correct! I have a js file and a button. When i click to button, i would like to execute another js file in my div. That js file executes some codes and display some results. Your code is ok but works in html section. Could you please divide the page %30-%70 vertically and put a button in the first div. When clicking the button, please execute another js which displays hello world in the second div. Please do them only in js window. – Opti Feb 08 '16 at 14:20
  • Please check the updated demo @ http://codepen.io/anon/pen/WrYQLX and replace "urlforyourscript" in js window with your script url – Arun Sharma Feb 08 '16 at 14:41
  • Ok, Thanks Arun but it displays in another page. $("#trackinginfo").html( '' ); or $.getScript("js/tracking.js"); I could not make it display in trackinginfo div dynamically! – Opti Feb 08 '16 at 14:53
  • Can you create a fiddle for this and let me inspect? – Arun Sharma Feb 08 '16 at 14:55
  • lets continue on your pen. I created a js file very simple : document.write("Hello World!");alert('aaaaaa'); Here : https://1fichier.com/?m01luth44c I put this link to $.getScript("https://1fichier.com/?m01luth44c"); alert function works but i can not see document.write in result div. – Opti Feb 08 '16 at 17:02
  • let me look into this. – Arun Sharma Feb 08 '16 at 17:08
  • Lets try writing directly to result div instead of document write. Replace your js file content with this: document.getElementById("result").innerHTML = "Hello World!"; alert('aaaaaa'); – Arun Sharma Feb 08 '16 at 17:36
  • Ok, here is my real js :https://1fichier.com/?lomifn8djt I can't make it run. This js takes an rss feed, parse and display. It works well when i call with – Opti Feb 08 '16 at 18:33