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 linkhref
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
Post a Comment