0
Dynamically adding script in html, not working
I want to add a script at the end of a tag but it is not working. Here I have already added script so it's working. https://code.sololearn.com/W5A4a14A7a38/?ref=app Here I have tried to add script later but it's not working. https://code.sololearn.com/Wa40a24A03A1/?ref=app (desktop)
6 Respuestas
+ 2
harshit
You can try like this
function addScript( src ) {
var s = document.createElement( 'script' );
s.setAttribute( 'src', src );
document.body.appendChild( s );
}
document.addEventListener("DOMContentLoaded", function(event) {
addScript ("https://platform.twitter.com/widgets.js");
});
0
I Am AJ ! Do you know why my code is not working, it was working with normal html but not with script.
0
harshit
On Sololearn I don't think dynamic script will work but on desktop browsers sure it will work because we are already doing like that.
0
I Am AJ ! This is not working in desktop also.
https://code.sololearn.com/Wa40a24A03A1/?ref=app
0
Btw. the problems seems to be that Sololearn interprets the JS as HTML if it includes a script tag for some reason...
0
Aaron Eberhardt it is same with locally also.