0

in my html I have:

<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
console.log('hello');
</script>

and I get nothing in console, but as soon as I remove all attributes in the script tag:

<script>
console.log('hello');
</script>

I can see the output in console. Yesterday everything worked fine, but today something is wrong.

Victor Di
  • 988
  • 10
  • 16

3 Answers3

1

You can't have both a src and code inside your script

What you should do:

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous">
</script>

<script>
  console.log('hello');
</script>
31piy
  • 23,323
  • 6
  • 47
  • 67
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
0

In Javascript you can not put code with src file. For that you must have to write separate include javascript file code and other javascript code like below.

Here you can include 3rd party javascript or jquery file like this:

    <script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>

And for additional javascript code you can write like this:

<script>
console.log('hello');
</script>
Kaushik Andani
  • 1,252
  • 1
  • 14
  • 22
0

Actually, Script Not Support Src and Others Code in the one Script tag

The pure javascript Normally Support console.log and alert() not needed for any others library or jquery.

if you try this code here

<script>
  console.log("Hello Console");
</script>

--- Thnk You ----

Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26