When playing code from the Brackets editor, everything works, functions are called.
But if you try to open index.html in the browser and trigger an event, the browser reports an error - the function was not found. What I just did not try and what info I didn’t put into script tags - nothing helps, only Yandex works, all other browsers do not see the function or scripts.

Code:

 function img_up(arg_src){ var div_all = document.createElement('div'); div_all.id="div_all_id"; document.body.appendChild(div_all); var div_tx = document.createElement('div'); div_tx.id="div_image"; document.body.appendChild(div_tx); div_tx.innerHTML="<img src="+" ' "+arg_src+" ' "+" onclick='img_dw()' >"; } function img_dw(){ var remel=document.getElementById("div_image"); remel.parentNode.removeChild(remel); var rem_ove=document.getElementById("div_all_id"); rem_ove.parentNode.removeChild(rem_ove); } 
  #div_all_id{ position:fixed; width: 100%; height: 100%; background: black; opacity: 0.7; } #div_image{ position:fixed; background: black; color: red; } #div_image img{ position:fixed; padding-left: 10%; padding-right: 10%; padding-top: 5%; width: 80%; } #galary{ position: absolute; } #galary img{ width: 200px; } 
 <html> <head> <link rel="stylesheet" href="galary.css" type="text/css" media="screen"> <script type="text/javascript" src="galaryjs.js"></script> </head> <body> <div id="galary"> <img src="1.jpg" onClick="img_up(src)" > <img src="2.jpg" onClick="img_up(src)" > </div> </body> </html> 

  • although it seems to work here, but it is not clear why it does not work on my browser. The script is simple - the gallery, you click on the small picture, the big picture comes out, you push the big one and it hides remain small again - PeteGr
  • Scripts need to be connected at the end of the document, after the body . Or use the event DOMContentLoaded / window.loaded - Mr. Black
  • onclick='img_up(this.src);' so more correct. And more advice, do not use any programs for writing code that does not require compilation. It will be enough to text editor Sublime Text or Notepad++ - Mr. Black
  • Tell me, are the files in the developer console visible as connected? In the sources tab of the Chrome browser, for example - smellyshovel
  • four
    @Doofy do not teach bad - Pavel Mayorov

1 answer 1

You can simply call the function directly from the js console or execute

 console.log('файл js подключен'); 

in the file galaryjs.js

If both options do not work, then the path to the file galaryjs.js is incorrect