Including javascript library from HTML body

I want to include a javascript library to my HTML page from inside my HTML body. i included the following script in my body part :

<script type = "text/javascript" >
var scriptHeader = document.createElement('script');
scriptHeader.setAttribute("src", '' );
if (typeof scriptHeader!="undefined") {
    // alert( "Success!!" );
else {


Now in I call my JS as

<script type = "text/javascript">
var plot = new Dygraph( 
               // ... create new graph

With out the 'alert', this is not working. It is throwing

ReferenceError: Dygraph is not defined

I assume this is a sync issue. How can I solve this?


What about to use $.getScript ?

$.getScript("someScript.js", function () {
    // use it here


Without jQuery:

var el = document.createElement('script');
el.async = true;
el.src = '';
el.onload = function(){
    // use here

el.onerror = function(){

document.head.appendChild( el );

Here is fiddle

Need Your Help

Issue with chaining Required Field and Regular Expression validators for Textbox controls

c# validation webforms

I'm trying to implement a form validation with and I have tried every solution suggested here but the best one was on so far.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.