Good day! Help Wanted! In general, everything works fine in the sandbox. http://jsfiddle.net/zawex/bmnUG/5/

(the task is to click on the image of the output of the block, and on click to any place except the block, to close it)

However, when I try to put it into practice (I have already tried to just in html clean, locally) the event when I clicked on the image does not work. I connect only jquery-1.9.1 - the last.

Persistently do not understand what is wrong. And why this “what” is wrong. спасибо advance.

upd. code that I insert

 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> <title>vsd</title> <link rel="stylesheet" type="text/css" href="mysite.css"> <script src="jquery-1.9.1.js" type="text/javascript"></script> </head> <body> <script language="JavaScript" type="text/javascript"> *** /*скрипт аналогично Jsfiddle */ </script> /*хтмл код*/ </body> </html> 

    3 answers 3

    I know that when copying with Jsfiddle, there is a problem with line breaks, and an error is thrown at the console. Try manually rewriting from there, or replace line breaks with your own. The best way to check is to run the entire code in one line.

    • Unfortunately, it did not help ( - zawex

    There, the execution of scripts on load is set, i.e. after loading the document. If you simply copy the code and you do not add a subscription to the load event, then your code is not equivalent to the code in fiddle.

      In your case when the code is executed

       var btn = $('#cartsho'), ovl = $('.overlay'); 

      these elements have not yet been added to the DOM, and accordingly - selectors will return 0 elements. For correction - you can move the announcement of this script after Html

       <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> <title>vsd</title> <link rel="stylesheet" type="text/css" href="mysite.css"> <script src="jquery-1.9.1.js" type="text/javascript"></script> </head> <body> /*хтмл код*/ <script language="JavaScript" type="text/javascript"> //когда выполняется это код - уже все html элементы доступны *** /*скрипт аналогично Jsfiddle */ </script> </body> </html>