Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery not executing

Posted on 2010-08-23
4
Medium Priority
?
341 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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

782 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