Why is my jQuery not binding my event?

I thought I understood jQuery, obviously not. Why is the first click registered in this example, but not the second?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4

/strict.dtd">
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.min"/>
<script type="text/javascript">

    captureKeys = function(event)
    {
    alert("foo");
    }
    $(document).ready(function()
            {
        $('#UsingJQuery').bind('keyup', function(){alert('bar');});
            });

</script>
</head>
<body id="contentText" >
    <input type="text" id="UsingPlainJavaScript" onkeyup="captureKeys()"/>
  <input type="text" id="UsingJQuery"/>

</body>
</html>

EDIT: Ok, I fixed the typo, but it still doesn't work.

+3
source share
3 answers

This requires trouble:

<script type="text/javascript" src="jquery-1.4.2.min"/>

You need </script>to have valid markup

<script type="text/javascript" src="jquery-1.4.2.min"></script>

This is a big NoNo and can be the cause of your problem. Another thing is that your name is not .js? Make sure yours jQuery libhas the correct name.

Link: http://www.w3.org/TR/xhtml1/#C_3

+4
source

UsingJQuery ( U), UsingJQuery.

$('#UsingJQuery').bind('keyup', function(){alert('bar');});

.

Update:

- , . .: http://jsfiddle.net/H2xye/

, jQuery :

src="jquery-1.4.2.min.js"

.js . , , , .
.

Update2: . jAndy </script>. , , !

+3

Please change from

<script type="text/javascript" src="jquery-1.4.2.min"/>

to

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

+1
source

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


All Articles