Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <div>
  2. <p><a href="#">it jumps</a></p>
  3. <p><a href="#">it jumps</a></p>
  4. <p><a href="#">it jumps</a></p>
  5. <p><a href="#">it jumps</a></p>
  6. <p><a href="javascript:void(0);" id="jsSolution">no jumps - jsSolution</a></p>
  7. <p><a href="#" id="jqSolution">no jumps - jqSolution</a></p>
  8. <p><a href="#!">no jumps - html Solution</a></p>
  9. <p><a href="#" id="problem">how to prevent this from jumping - javascript solution in the add() function</a></p>
  10. </div>
  11.  
  12. $(function(){
  13. function inner(){
  14.  
  15.  
  16. //prevent from scrolling to top here - solution is needed here;
  17.  
  18. return 4;
  19. }
  20. function add() {
  21. alert('how to prevent jumping to top in the add function');
  22. var counter = 0;
  23. var res=inner();
  24. alert(res);//4
  25. //some code goes here
  26. //and here
  27. //this doesn't work e.preventDefault();
  28. return counter;
  29. }
  30. $('#jqSolution').click(function(e) {
  31. // do something fancy
  32. return false; // prevent default click action from happening!
  33. e.preventDefault(); // same thing as above
  34. });
  35. $('#problem').click(function(e) {
  36. add();
  37. });
  38. });
  39.  
  40. div{
  41. border:1px solid red;
  42. width:200px;
  43. }
  44. p{
  45. padding:50px;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement