javascript - how can i interchange of two elements in html via js or jquery on click one of them? -


<a href="javascript:" id="highlowrating" tabindex="0"> <a href="javascript:" id="lowhighrating" tabindex="1"> 
$('#lowhighrating').click(function(){     // interchange highlowrating" , if nothing.  }); $('#highlowrating').click(function(){     // interchange lowhighrating" , if nothing. }); 

i need interchange positions of links if click 1 of them , if on corresponding position nothing,i tried .toggle() changing position, little confused here.

you can use insertafter() , insertbefore() inserting element after/before element.

$("#highlowrating, #lowhighrating").click(function(){      var index = $(this).index() - 1;      if (index != $(this).attr("tabindex")){          if (index == 0)              $(this).insertafter($(this).siblings("a"));          else              $(this).insertbefore($(this).siblings("a"));      }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a href="javascript:" id="lowhighrating" tabindex="1">b</a>  <a href="javascript:" id="highlowrating" tabindex="0">a</a>


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -