Uncaught TypeError: Object [object Object] does not have a 'on' method

i created an appendScript function that will be called in the event with the click of a button. My functional code

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.imtqy.com/bootstrap/1.4.0/bootstrap.min.css" body.appendChild(v_css); } 

when i click the button i get an error

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

can anyone help how to solve this error?

+4
source share
1 answer

Your version of JQuery (1.5.2) and Bootstrap (2.3.2) are not compatible. Update 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+ jquery. So try updating it to the latest version.

When you download the latest version of boostrap (2.3.2) , it provides you with version 1.9.1 of jquery along with the package, so you can try updating at least to this version so that everything works as expected.

+8
source

Source: https://habr.com/ru/post/1487988/


All Articles