| | |
[ask] JQuery preventDefault is not working
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2009
Posts: 20
Reputation:
Solved Threads: 0
Hi,
I want create a page which has animation at the bottom of that page. I use jQuery to do that..
this is the way I do it
and this is the jquery
When I run the code, all animation run very well except the page always scroll to the top. I try to change the href attribute to javascript:void(0); but it still run like that..
How can I fix it?
Thanks before,
Sorry for my English..
I want create a page which has animation at the bottom of that page. I use jQuery to do that..
this is the way I do it
html Syntax (Toggle Plain Text)
<a href="#" class="animation">Animate this</a>
and this is the jquery
javascript Syntax (Toggle Plain Text)
$(document).ready(function() { $('a.animation').click(function(e) { e.preventDefault(); //animation goes here; }); });
When I run the code, all animation run very well except the page always scroll to the top. I try to change the href attribute to javascript:void(0); but it still run like that..
How can I fix it?
Thanks before,
Sorry for my English..
learning to live..
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Solved Threads: 0
0
#2 Oct 22nd, 2009
You could do away with your anchor tags and use span instead. Then use CSS to style the cursor to pointer so it shows up as clickable like a link.
•
•
•
•
Hi,
I want create a page which has animation at the bottom of that page. I use jQuery to do that..
this is the way I do it
html Syntax (Toggle Plain Text)
<a href="#" class="animation">Animate this</a>
and this is the jquery
javascript Syntax (Toggle Plain Text)
$(document).ready(function() { $('a.animation').click(function(e) { e.preventDefault(); //animation goes here; }); });
When I run the code, all animation run very well except the page always scroll to the top. I try to change the href attribute to javascript:void(0); but it still run like that..
How can I fix it?
Thanks before,
Sorry for my English..
•
•
Join Date: Jul 2009
Posts: 20
Reputation:
Solved Threads: 0
0
#4 Oct 23rd, 2009
Hi all..
I have tried all of your suggestion. But, it didn't work.
But, I just realize that when animations run, actually the page do not scroll to the top of the page. It just scroll to some pixels to the top. But it is disturbing. I'm starting to find where the page actually go when the animations run or may be there is an error in my code.
Thanks all,
I will post it here later if I find it.
But, if someone who has any others suggestion, I hope it will help me..
I have tried all of your suggestion. But, it didn't work.
But, I just realize that when animations run, actually the page do not scroll to the top of the page. It just scroll to some pixels to the top. But it is disturbing. I'm starting to find where the page actually go when the animations run or may be there is an error in my code.
Thanks all,
I will post it here later if I find it.
But, if someone who has any others suggestion, I hope it will help me..
learning to live..
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Solved Threads: 0
0
#5 Oct 23rd, 2009
I think you need to look elsewhere for the problem. I have tested the following and no scrolling occurs.
html code:
javascript code:
css code:
I've posted a simple page to demonstrate:
Animate Code Test
If you are still having problems, you need to post your other code so we can help.
html code:
html Syntax (Toggle Plain Text)
<div id="padding"></div> <span class="animate">Animate this.</span>
javascript Syntax (Toggle Plain Text)
$(document).ready(function() { $('span.animation').click(function() { alert("Animate!"); }); });
css Syntax (Toggle Plain Text)
#padding {height:1500px;} .animate {cursor:pointer;}
Animate Code Test
If you are still having problems, you need to post your other code so we can help.
•
•
•
•
Hi all..
I have tried all of your suggestion. But, it didn't work.
But, I just realize that when animations run, actually the page do not scroll to the top of the page. It just scroll to some pixels to the top. But it is disturbing. I'm starting to find where the page actually go when the animations run or may be there is an error in my code.
Thanks all,
I will post it here later if I find it.
But, if someone who has any others suggestion, I hope it will help me..
![]() |
Similar Threads
- JQuery Not working in Drupal (PHP)
- jQuery XML manipulation NOT WORKING in Internet Explorer (JavaScript / DHTML / AJAX)
- jQuery-ui Sortable Portlets in Passing Array to php (PHP)
- [jQuery] Create a draggable on the mousedown event (JavaScript / DHTML / AJAX)
- jQuery and Back-Tracked URL's? (JavaScript / DHTML / AJAX)
- Ajax Tabs, half working (JavaScript / DHTML / AJAX)
- JQuery Accordion Menu (Help Needed) (JavaScript / DHTML / AJAX)
- Can't put 2 Javasript working in the same page! (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Change form input text using Javascript/Dom
- Next Thread: Dynamic select boxes not setting values on page load in safari
| Thread Tools | Search this Thread |
.net 2.0 adobe adobeacrobat adobereader ajax ajaxcode ajaxexample ajaxhelp animate api array asp asp.net automatically box bug c# cakephp cart checkbox class close codeinjection codes createrange() debugger decimal dependent dom download element email events explorer external file firefox flash form getselection google gwt hackers hiddenvalue highlightedword html htmlform iframe images internet java javascript jquery jsf jsfile jsp libcurl logfiles loop math microsoft mp4 mysql news paypal pdf php post problem programming regex registrationform runtime safari scale scroll search security select session shopping software synchronous tables text textbox toggle treeview validation variables vulnerability w3c web webservice window windowofwords wysiwyg xml zeroday






