Opti February 2016

Loading js file into div using jquery

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?

Answers


Arun Sharma February 2016

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

Post Status

Asked in February 2016
Viewed 3,511 times
Voted 5
Answered 1 times

Search




Leave an answer