My first dig in jQuery

I am a complete newbie to jQuery. I also know little about JavaScript, except for some very simple things.

I follow this guide here: http://docs.jquery.com/How_jQuery_Works

And nothing works !:-)

I created a folder on my computer hard drive here: C: \ rnd \ jQuery

Then in this folder I placed the jquery.xxjs file, which I downloaded from the jQuery website, and created the test.html file and wrote the following code in it:

<!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery-1.4.2.js"></script>

    <style type="text/css">
      a.test { font-weight: bold; }
    </style>

    <script type="text/javascript">
      $.(document).ready(function() {
        $("a").addClass("test");
        $("a").click(function(event) {
          alert("Thanks for visiting.");
          event.preventDefault();
        });
      });
    </script>
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
  </body>
</html>

This is just the normal behavior associated with my answer to the jQuery site. I ran it in Chrome, IE and Firefox. I have JavaScript enabled in browsers. It’s all the same everywhere. He does not do anything that I expected from him. It just brings me to the site.

IE, , script . "" , , , , .

, :

$("a").hide("slow");

:

<!doctype html>
<html>
  <head>
    <script type="text/javascript" src="jquery-1.4.2.js"></script>

    <style type="text/css">
      a.test { font-weight: bold; }
    </style>

    <script type="text/javascript">
      $.(document).ready(function() {
        $("a").addClass("test");
        $("a").click(function(event) {
          alert("Thanks for visiting.");
          event.preventDefault();
          $("a").hide("slow");
        });
      });
    </script>
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
  </body>
</html>

Firefox Chrome, IE , , jQuery .

(function($) {
  $.fn.textDropShadow = function(){
    $(this).html('<span class="jq-shadow">'+$(this).html()+'</span><span>'+$(this).html()+'</span>');
    return $(this);
  }
})(jQuery);

, , JavaScript - jQuery.

. .

Update: HTML-, XHTML. , HTML, script. ! HTML?

+3
4

. . $ , .

$.(document).ready(function()
 ^--- remove the .!

:

$(document).ready(function() 
+16

-, , jQuery, , jQuery ( )

<script type="text/javascript" src="{path to jquery.x.x.js}" ></script>

, $(document).ready(function() {});

not $. (document)

+4

, ​​ $.document, jquery.

, javascript, , $. jquery , - $, - $ jquery init.. .

// , jQuery, .

jQuery(document).ready(function($) {
    $('#...');
});
+2

:

<script type="text/javascript" src="jquery.js"></script>

, , .

+1

Source: https://habr.com/ru/post/1757139/


All Articles