Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-15-2008, 12:41 AM   PM User | #1
FWDrew
Regular Coder

 
FWDrew's Avatar
 
Join Date: Apr 2008
Location: Missouri
Posts: 380
Thanks: 38
Thanked 45 Times in 43 Posts
FWDrew is on a distinguished road
Cannot get jQuery to function

Hi all,

Im pretty frustrated with this, as I feel like I am missing something really simple but just cant figure it out. Basically I was going to use jQuery to animate the "search" image at the top. After this didnt work, I realized I couldnt get any jquery to work

So I went back to basics to try a very simple script and just cant get any jQuery to work.

Code:
Code:
$(document).ready(function(){
   ("a#searchAnimate").click(function(event){
   alert("As you can see, the link no longer took you to jquery.com");
   event.preventDefault();
   });
 });
Some of Relevenat HTML:
Code:
<ul><li id="searchBox">
				<?php include (TEMPLATEPATH . '/searchform.php'); ?>
			</li></ul>
	<div style="display:block;"><a href="http://jquery.com" id="searchAnimate" title="Search"><img class="search" src="wp-content/themes/splat!/style/images/search.png" alt="Search" /></a></div>
Test page is here.

If you view the page, you can see the scripts are being called properly in the head and appear inf firebug, I thought it might have been a path issue, so threw in the absolute path and still couldnt get it to work.

So, any ideas what have I done wrong? Appreciate any help or advice

Best Regards,

Drew

Edit-Just would like to add before someone tells me to correct them, the 4 html markup errors are just from the free host that I use tracking script, the actual page and markup is valid
__________________
Dev-Tips.com || Employee at the Envato Network || My Portfolio
FWDrew is offline   Reply With Quote
Old 10-15-2008, 04:32 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
You missed:
Code:
$(document).ready(function(){
   $("a#searchAnimate").click(function(event){
   alert("As you can see, the link no longer took you to jquery.com");
   event.preventDefault();
   });
 });
Also, sincce id is unique in every page, you can just remove highlighted:
Code:
("a#searchAnimate")
Hope that helps.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
FWDrew (10-15-2008)
Old 10-15-2008, 07:37 AM   PM User | #3
FWDrew
Regular Coder

 
FWDrew's Avatar
 
Join Date: Apr 2008
Location: Missouri
Posts: 380
Thanks: 38
Thanked 45 Times in 43 Posts
FWDrew is on a distinguished road
Hi Rangana,

Wow, I feel pretty embarrassed that I missed that. Thank you very much. However, I still cannot jQuery to function as I want it to. Take for example this:
Code:
$(document).ready(function(){
   $("#searchAnimate").click(function(event){
   event.preventDefault();
   $(this).hide("slow");
 });

});
I still cant get this very simple script to work, any ideas? I think I need to step away from it and let my eyes rest for a bit

Best Regards,

Drew
__________________
Dev-Tips.com || Employee at the Envato Network || My Portfolio
FWDrew is offline   Reply With Quote
Old 10-15-2008, 07:46 AM   PM User | #4
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Try to interchange the two:
Code:
 event.preventDefault();
   $(this).hide("slow");
event.preventDefault is the same as if you return false on JS which cancels any event from the point of declaration forward.

Hope that helps.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 10-15-2008, 07:56 AM   PM User | #5
FWDrew
Regular Coder

 
FWDrew's Avatar
 
Join Date: Apr 2008
Location: Missouri
Posts: 380
Thanks: 38
Thanked 45 Times in 43 Posts
FWDrew is on a distinguished road
Quote:
Originally Posted by rangana View Post
Try to interchange the two:
Code:
 event.preventDefault();
   $(this).hide("slow");
event.preventDefault is the same as if you return false on JS which cancels any event from the point of declaration forward.

Hope that helps.
Hey Rangana,

Thanks again, but I am still having no luck, here is my updated code:
Code:
$(document).ready(function(){
   $("#searchAnimate").click(function(){
   $(this).hide("slow");
   return false;
 });

});
About ready to pull my hair out, just dont know why I cant get this right. I really appreciate all of your help

Best regards,

Drew
__________________
Dev-Tips.com || Employee at the Envato Network || My Portfolio
FWDrew is offline   Reply With Quote
Old 10-15-2008, 08:10 AM   PM User | #6
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Working fine at my end.

See testing example:
Code:
<script type="text/javascript" src="http://premiumthemes.net84.net/wordpress/wp-content/themes/splat!/style/scripts/jquery-1.2.6.min.js"></script>
<script>
$(document).ready(function(){
   $("#searchAnimate").click(function(){
   $(this).hide('slow');
   return false;
 });

});
</script>
<ul><li id="searchBox">
test
			</li></ul>
	<div style="display:block;"><a href="http://jquery.com" id="searchAnimate" title="Search"><img class="search" src="http://rangana.moonylist.com/images/Picture7.jpg" alt="Search" style="width:350px;height:300px;"/></a></div>
Click on the image and it hides, nothing wrong (as far as I can see), or you expect it to do something else?
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Users who have thanked rangana for this post:
FWDrew (10-16-2008)
Old 10-16-2008, 04:40 AM   PM User | #7
FWDrew
Regular Coder

 
FWDrew's Avatar
 
Join Date: Apr 2008
Location: Missouri
Posts: 380
Thanks: 38
Thanked 45 Times in 43 Posts
FWDrew is on a distinguished road
Quote:
Originally Posted by rangana View Post
Working fine at my end.

See testing example:
Code:
<script type="text/javascript" src="http://premiumthemes.net84.net/wordpress/wp-content/themes/splat!/style/scripts/jquery-1.2.6.min.js"></script>
<script>
$(document).ready(function(){
   $("#searchAnimate").click(function(){
   $(this).hide('slow');
   return false;
 });

});
</script>
<ul><li id="searchBox">
test
			</li></ul>
	<div style="display:block;"><a href="http://jquery.com" id="searchAnimate" title="Search"><img class="search" src="http://rangana.moonylist.com/images/Picture7.jpg" alt="Search" style="width:350px;height:300px;"/></a></div>
Click on the image and it hides, nothing wrong (as far as I can see), or you expect it to do something else?
Nope, that works great. It was really strange, I got it to work if I put the script hard coded on the html instead of linking to it. I then tried linking to it again and it worked

Either way, im satisfied, thanks very much for all of your help Rangana

Best Regards,

Drew
__________________
Dev-Tips.com || Employee at the Envato Network || My Portfolio
FWDrew is offline   Reply With Quote
Old 05-20-2009, 10:31 AM   PM User | #8
kerry1803
New to the CF scene

 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kerry1803 is an unknown quantity at this point
Cant get JQuery To Work, Pls Help

hi, I'm using eclipse for development and trying oout jQuery for the first time, I can't seem to get the following working.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<style type="text/css">
#box
{
background:red;
width:80px;
height:80px;
}
</style>

<script type="text/javascript">
$(document).ready(function(){
$('a').click(function() {
$('#box').fadeOut();
});
});

</script>

<title>Test</title>
</head>
<body>
<div id="box"></div>
<a href="#">Link</a>

</body>
</html>
kerry1803 is offline   Reply With Quote
Old 05-20-2009, 01:42 PM   PM User | #9
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Make a new thread for your question.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 AM.


Advertisement
Log in to turn off these ads.