Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Object [object Object] has no method 'on'

i made a function appendScript which will be called on a button click event my function code is

function appendScript()
{var v_js;
var head= document.getElementsByTagName('head')[0];
      v_js = document.createElement('script');
    v_js.type = 'text/javascript';
v_js.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
    head.appendChild(v_js);
var body = document.getElementsByTagName('body')[0];
v_js =document.createElement('script');
v_js.type="text/javascript" ;
v_js.src = "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js";

body.appendChild(v_js);
var v_css= document.createElement('link');
v_css.rel= "stylesheet";
v_css.type = "text/css" ;
v_css.href="http://twitter.github.io/bootstrap/1.4.0/bootstrap.min.css"
body.appendChild(v_css);
}

when i click on the button i am getting error

Uncaught TypeError: Object [object Object] has no method 'on' bootstrap.min.js:6
(anonymous function) bootstrap.min.js:6
(anonymous function)

can any one please help how to resolve this error ??

like image 437
Ritesh Mehandiratta Avatar asked Feb 16 '23 03:02

Ritesh Mehandiratta


1 Answers

Your version of JQuery(1.5.2) and Bootstrap (2.3.2) are not compatible. Upgrade your version of Jquery. Bootstrap is looking for on() which is not available in your version(1.5.2). .on() is available from version 1.7+ of jquery. So try upgrade it to the latest version as possible.

When you download the latest version of boostrap(2.3.2) it provides you 1.9.1 version of jquery along with the package, so you may want to try upgrading at least to that version to ensure everything is working as expected.

like image 64
PSL Avatar answered Feb 27 '23 11:02

PSL