jQuery click listener doesn't work properly


#1

what did I do wrong?


#2

please share the exercise url and code so we can run your code in the exercise

This is the old course, the environment is no longer supported.


#3

https://www.codecademy.com/en/courses/web-intermediate-en-jfhjJ/0/5#


#4

i asked also for your code? The exercise url would just load my own code, but i needed it to find the exercise


#5

The instructions show add HTML button with the id of change_me,
So your button tag may .
And also the selector in script.js at line 2 would be $("#change_me") instead of $("#button")

In selector, you should make sure id comes after #.


#6

here is my code:
in index.html doc:

<!DOCTYPE html>
<html>
	<head>
		<title></title>
		<link rel="stylesheet" href="style.css" />
		<script src='script.js' type="text/javascript"></script>
	</head>
	<body>
	<button id="button">Click Me!</button>
	<div id="change_me"></div>
	<style>
#button {
    background-color: pink;
    color: white;
    width: 200px;
    height: 50px;
}

	</style>
	</body>
</html>

in script.js doc:

   $(document).ready(function(){
     $("#button").click(function(){
         alert("I have been changed!");
         $(".hide_div").hide();
         //action
     });
   });

#7


#8

When it is clicked, change the .text() of change_me to “I have been changed!”

you need to use .text(), not alert()