/    Sign up×
Community /Pin to ProfileBookmark

It does not work when jQuery is found

Hi there,

I’m reading book “Applied jQuery” by Jay Blanchard. Example 1-1 is strange. The code is as below. Becasue there is no inc folder in the specified place, so no jquery-1.5.min.js is there. But when “New Content” is clicked, the page is replaced by 1-2.html entirely, not just #rightContent (BTW, Firebug can not expand this Script). When a right path is provided to 1-1.html, the button is not worked: when clicks, nothing is happened (this time Firebug can expand the Script). What’s the problem here?

[CODE]
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″ />
<title>Progressive Enhancement Example 1-1</title>
<script type=”text/javascript” src=”../inc/jquery/jquery-1.5.min.js”></script>
<style type=”text/css”>
html, body {
height: 100%;
}
body {
min-height: 100%;
margin: 0px;
text-align: left;
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
background-color: #FFFFFF;
}
#header {
background-color: #0000FF;
color: #FFFFFF;
padding: 5px 5px 5px 10px;
}
#leftContent {
width: 20%;
min-height: 100%;
bottom: 0px;
background-color: #FFFF00;
color: #FFFFFF;
vertical-align: top;
padding: 10px 0px 0px 20px;
float: left;
}
#rightContent {
width: 75%;
margin-left: 20px;
padding-top: 10px;
background-color: #FFFFFF;
vertical-align: top;
float: left;
}
#clear {
clear: both;
float: none;
height: 0px;
}
</style>
<script type=”text/javascript”>
$(document).ready(function() {
$(“#anchor”).click(function(event) {
$(“#rightContent”).load(“1-2.html #rightContent > p”);
event.preventDefault();
});
$(function() {
$(‘a[rel*=”external”]’).click( function(e) {
window.open(this.href);
e.preventDefault();
});
});
});
</script>
</head>
<body>
<div id=”header”><h2>Progressive Enhancement Example</h2></div>
<div id=”clear”></div>
<div id=”leftContent”>
<a href=”1-2.html” id=”anchor” >New Content</a><br />
<a href=”http://www.google.com” rel=”external”>Google</a>
</div>
<div id=”rightContent”></div>
</body>
</html>
[/CODE]

Thanks,

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottMar 10.2012 — ...no jquery-1.5.min.js is there. But when "New Content" is clicked, the page is replaced by 1-2.html entirely...[/quote]

The link's href points to 1-2.html, so when jQuery isn't around to alter the behavior, the link will behave like a regular link.

When a right path is provided to 1-1.html, the button is not worked: when clicks, nothing is happened (this time Firebug can expand the Script). What's the problem here?[/quote]

Firebug's Console should have an error message for you, but I suspect it's because this page isn't being accessed through a web server. jQuery's load method uses ajax, and ajax doesn't work correctly unless it through a web server.
Copy linkTweet thisAlerts:
@wowauthorMar 10.2012 — Thanks a lot, Jeff Mott, you explain this issue very well. I think "Applied jQuery" needs to change the bug of jQuery path and tell its readers the example has to be run from a web server in order to make it worked as expected. It can not work if just double clicks on the file and open it in a browser.
×

Success!

Help @wow spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...