1

I'm not able to run a simple script in a web which I inject jQuery So lets imagine an almost blank web:

<html>
<head>
 <title>Demo</title>
</head>
<body>

</body>
</html>

Then I open DOM and insert this:

<html>
<head>
 <title>Demo</title>
 <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
</head>
<body>
 <button class="btn btn-danger btn-block" id="demo">Demo</button>

<script>
$(function(){
 $(document).on('click','#demo',function(){
  alert("Hello World!");
 });
});
</script>
</body>
</html>

And thats not working :( only works if the web starts with all the code at first, but don't when injecting. Is there a way to make it possible? Thanks a lot and greetings :)

jacohawk
  • 21
  • 1
  • 3
    How do you inject the code? – t.niese Dec 25 '19 at 16:16
  • @t.niese I just type f12 in web browser and put the code inside de loaded page inside DOM, just replace the old for the new one – jacohawk Dec 25 '19 at 16:24
  • JavaScript you paste into an element from the inspect window will not be evaluated and run by the browser. You can paste the js code in the console and that would run it if you’re just testing stuff, or you can add the script to the actual html of the page so it’d run on page load – Wesley Smith Dec 25 '19 at 16:38

0 Answers0