Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Include a JavaScript file in another JavaScript file using jquery?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 132
    Comment on it

    We can achieve this using javascript or using jquery.Below methods demonstrate it.

    Method 1: Use any JavaScript to include another js file.

    Step 1: Add following function in your page.

    function includeScript(url)
    {    
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url;
        head.appendChild(script);
    }
    

    Step 2: Now call the below includeScript function, Where you want to include the js file .

    includeScript('/js/jquery-1.7.min.js');
    

    Other method is:-

    Method 2: Use jQuery to include another js file .

    Step 1: Add jQuery File in your webpage like this.

    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    

    Step 2: Just call the includeScript function like below code.

     jQuery(document).ready(function(){
        $.includeScript('/js/jquery-1.7.min.js');
    });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: