Simple jquery/javascript switch href -



Simple jquery/javascript switch href -

i have link:

<div name="top"> <!-- code --> <a class="mylinktotop" href="#bot">click</a> <!-- code --> <div name="bot">

i wish alter href attribute when it's clicked. i'm using script:

<script> $(".mylinktotop").click(function(){ $("a.mylinktotop").attr("href","#top"); }); </script>

but have 2 problems:

when click link href changes, action sends me #top, instead of #bot. after that, want href switch between #top , #bot. don't know how thinking changing class value "toggleclass()" don't think best utilize problem.

this move current href on link , alter it:

$(".mylinktotop").click(function(e){ e.preventdefault(); window.location.href = this.href; this.href = this.hash === "#top" ? "#bot" : "#top"; });

javascript jquery html class href

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -