Solved

Jquery not executing

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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

623 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