Solved

Jquery not executing

Posted on 2010-08-23
4
338 Views
Last Modified: 2012-05-10
the code seems to be working when i do;
$(document.body).click(function ()

but not with a specific id


<!DOCTYPE>
<html>
	<head>
		<title>TEST</title>
		<link href="style.css" media="screen" rel="stylesheet" type="text/css" />
                     <script src="http://code.jquery.com/jquery-latest.min.js"></script>
	</head>
	<body>
	<script>

	$('#location').click(function ()
	{
	if ($("#aa:first").is(":hidden"))
	{
	$("#aa").slideDown("slow");
	}
	else
	{$("#aa").hide();
	}
});</script>




 <div id="location" class="location"><a href="#"> <div id="aa"></div></div>



	</body>

</html>

Open in new window

0
Comment
Question by:fb19071907
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33503701
Check this :


<!DOCTYPE>
<html>
<head>
<title>TEST</title>
<link href="style.css" media="screen" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
	$(document).ready(function() {
		$('#location').click(function () {
			if ($("#aa:first").is(":hidden")) {
				$("#aa").slideDown("slow");
			}
			else {
				$("#aa").hide();
			}
		});
	});
</script>
</head>
<body>
<div id="location" class="location"><a href="#">Click</a><div id="aa">HELLO</div></div>
</body>
</html>

Open in new window

0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 33504776
I believe you're missing a closing </a> tag in your code. Other than that, I would relocate your script into <head> part of code, just as asleakim971 pointed out.
0
 
LVL 15

Expert Comment

by:SRigney
ID: 33504947
inline javascript like that will work, but it must be after the item that it's trying to reference.

If you put it into the document ready function that leakim showed you, then the html will be finished loading before the javascript runs making the order not important.


CyberGhost, the recommendations for speed is CSS at the top of the page and javascript at the bottom of the page.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33514329
Thanks for the points!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question