Skip to content Skip to sidebar Skip to footer

Appending A Link With Jquery

I'm trying to add a link to my page depending on what page you're already on. I'm using Squarespace to build this site, so the easiest way for me to do this would be with Javascrip

Solution 1:

Your code seems to work fine however you can use else if statements instead of nested if statements:

if(loc == pageOne) {
    $("#pages").append("<div><ahref=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a></div>")
} else if (loc == pageOneB){
    $("#pages").append("<div><ahref=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a></div>")
} else if (loc == pageTwo){
    $("#pages").append("<div><ahref=\"http://design.optimus.com/projects\">Previous Page</a></div> ")
}​

Here is a demo: http://jsfiddle.net/Rba6w/

Solution 2:

see if this works

if(loc == pageOne) {
$("#pages").append('<div><ahref="http://design.optimus.com/projects?currentPage=2">Next Page</a></div>')
    }else{
  if(loc == pageOneB){
    $("#pages").append('<div><ahref="http://design.optimus.com/projects?currentPage=2">Next Page</a></div>')
  }else{
    if(loc == pageTwo){
     $("#pages").append('<div><ahref="http://design.optimus.com/projects">Previous Page</a></div>')
  }
 }
}

Solution 3:

Try this out:

switch(loc)
{
case pageOne:
  $("#pages").append('<div> <a href="http://design.optimus.com/projects?currentPage=2">Next Page</a> </div>');
  break;
case pageOneB:
  $("#pages").append('<div> <a href="http://design.optimus.com/projects?currentPage=2">Next Page</a> </div>');
  break;
case pageTwo:
  $("#pages").append('<div> <a href="http://design.optimus.com/projects">Previous Page</a></div>"');
  break;
}

Post a Comment for "Appending A Link With Jquery"