Solved

Jquery not executing

Posted on 2010-08-23
4
335 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now