Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div name="top">
- <!-- some code -->
- <a class="myLinkToTop" href="#bot">Click</a>
- <!-- some code -->
- <div name="bot">
- <script>
- $(".myLinkToTop").click(function(){
- $("a.myLinkToTop").attr("href","#top");
- });
- </script>
- $(".myLinkToTop").click(function(e){
- e.preventDefault();
- window.location.href = this.href;
- this.href = this.hash === "#top" ? "#bot" : "#top";
- });
- $(".myLinkToTop").on("click", function () {
- var $this = $(this), // cache "this as a jQuery object"
- href = $this.attr("href");
- if (href === "#bot") {
- setTimeout(function () {
- $this.attr("href", "#top");
- }, 100);
- } else {
- setTimeout(function () {
- $this.attr("href", "#bot");
- }, 100);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement