Jump to content


Photo

Chap3 P115 What's Worng With My Code?!


  • Please log in to reply
2 replies to this topic

#1 DP76

DP76

    Active Member

  • Members
  • PipPip
  • 43 posts

Posted 31 December 2013 - 08:16 AM

Hi all,
I hope someone can help me. I have been going through the book and have copied the code on p115. It doesn't work. I have checked and checked and checked. I cannot see what is wrong. Can you see an error? (jquery-1.10.2.min.js is the latest version)
All help greatly appreciated
I will include all three files.
class_test.html
<html>
	<head>
		<link href="styles/test_style.css" rel="stylesheet">
	</head>
<body>
	<div id="header" class="no_hover"><h1>Header</h1></div>
	<button type="button" id="btn1">Click to Add</button>
	<button type="button" id="btn2">Click to Remove</button>
	
	<script src="scripts/jquery-1.10.2.min.js"></script>
	<script src="scripts/my_test_scripts.js"></script>
</body>
</html>

my_test_scripts
$(document).ready(function() {
	$("#btn1").click( function() {
		$("#header").addClass("hover");
		${"#header").removeClass("no_hover");
	});
	$("#btn2").click( function() {
		$("#header").removeClass("hover");
		$("#header").addClass("no_hover");
	});
});
test_style
.hover {
	border: solid #f00 3px;
}
.no_hover {
	border: solid #000 3px;
}


#2 lemuel

lemuel

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 577 posts

Posted 01 January 2014 - 12:08 PM

Typo here:
${"#header").removeClass("no_hover");
That should be "(" in front of "#header".

#3 DP76

DP76

    Active Member

  • Members
  • PipPip
  • 43 posts

Posted 02 January 2014 - 03:20 AM

Thank you! Very well spotted! I can't believe I missed that




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users