1

I have a sort bar and I want to cage urls and titles on click. For example this link:

<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc ">Title ASC</a>

Should change to:

<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc ">Title DESC</a>

The links should go to the page and then switch to the new link after click.

How is this done? HTML5, Javascript or Jquery?

3 Answers3

0

I am not completly sure if this is it, but you might try and give a feedback, if possible.

<script>
function changeHref(_a) {
    var linkAsc = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc";
    var linkDesc = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc";

    console.log(_a);
    if (_a.id == "aOne") {
        document.getElementById(_a.id).href = linkDesc;
    } else {
        document.getElementById(_a.id).href = linkAsc;
    }
    return false;
}
</script>

HTML

<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc" id="aOne" onclick="changeHref(this);">Title ASC</a>
<br />
<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc" id="aTwo" onclick="changeHref(this);">Title DESC</a>
lockedz
  • 219
  • 7
  • 15
0

I think this work:

HTML

<a id="link" href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc ">Title ASC</a>

JS

$(document).ready(function () {
    if($("#link")[0].textContent == "Title ASC")
    {
        $("#link")[0].textContent = "Title DESC";
        $("#link")[0].href = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc"
    }
    else
    {
        $("#link")[0].textContent = "Title ASC";
        $("#link")[0].href = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc"
    }
});
DZanella
  • 243
  • 1
  • 8
  • I tried all the above and the URl and Title do not switch. I think onclick with visibility might work. Onclck one link appears, another click the link reverts. – user2821847 Aug 25 '15 at 19:42
0
$(document).ready(function () {
$("#a_id").click(function(){

  if($("#a_id").text() == 'Title ASC')
  {
    $("#a_id").attr("href","http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc");
    $("#a_id").text("Title DESC");
  }
  else
  {
    $("#a_id").attr("href","http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc");
    $("#a_id").text("Title ASC");
  }
});
});

<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc" id="a_id">Title ASC</a>
Mitre
  • 239
  • 1
  • 2
  • 11