<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Assignment 1</title>
<style>
.detail { padding: 5px;}
.hidden {display:none;}
.unhidden {display: block;}
</style>
</head>
<body>
<div class="container">
<ul class="list">
<li>
<div class="master">Pre-foundation</div>
<div class="hidden">
XYZ.......
</div>
</li>
<li>
<div class="master">Apple I</div>
<div class="hidden">
XYZ.....
</div>
</li>
<li>
<div class="master">Apple II</div>
<div class="hidden">
XYZ.....
</div>
</li>
<li>
<div class="master">Apple III</div>
<div class="hidden">
XYZ.....
</div>
</li>
<li>
<div class="master">Apple IPO</div>
<div class="hidden">
XYZ.....
</div>
</li>
</ul>
</div>
<script type="text/javascript"src="/Users/Documents/JS/jquery-1.6.2.js">
jQuery.noConflict();
function show_alert()
{
alert("x! I am an alert box!");
}
show_alert();
$(".master").click(function() {
alert ("hello");
});
</script>
</body>
I am having problems getting the click function to work. I am trying to expand the hidden text when the user clicks on the title of the paragraph.
The source of the jquery-1.6.2.js file is correct and I am able to open it in the browser. It also shows under the “script” tab of firebug.
If I delete the src=”/Users/Documents/JS/jquery-1.6.2.js” from the code, I am able to see an alert box firing from show_alert();. But when I add the “src = ..” in the code the show_alert(); stops working and I am not able to get handle to the ‘master’ class. What am I doing wrong?
I think the main issue is that you do not have your code wrapped with the jQuery ‘ready’ function. It needs to be wrapped in:
Since you are using $.noConflict() you need to use jQuery instead of its alias of ‘$’ after it is called:
Here is a jsfiddle of this all working.