Solved

Conditional Link URL - Easy Question

Posted on 2016-09-27
4
44 Views
Last Modified: 2016-10-12
Take a look at the following script.
A small block of links that will apear on various different pages.

The logic should be fairly simple to follow.

I need the link target addresses to vary according to the page or content that contains these links.

This might be based on URL?
It could also be based on some identifier or class contained in the surrounding content

Simpler the better - i.e, cSS. Javascrip if necessary.

Any suggestions ?


<table  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><a href=" if current page = A, then link = B "><a href=" if current page = C, then link = D ">Text 1</a></a></td>
    <td><a href=" if current page = E, then link = F "><a href=" if current page = G, then link = H ">Text 2</a></a></td>
    <td><a href=" if current page = I, then link = J "><a href=" if current page = K, then link = L ">Text 2</a></a></td>
  </tr>
</table>
0
Comment
Question by:arthur_raft2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Dr. Klahn
ID: 41819195
In Apache, nginx, or IIS?
0
 
LVL 42

Accepted Solution

by:
zephyr_hex earned 500 total points (awarded by participants)
ID: 41819917
Here is an example using jQuery

Fiddle Demo here

Given the following HTML:
<table id="myTable" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><a href="">Text 1</a></td>
  </tr>
</table>
<div id="myBtns">
  <input type="button" value="Page A">
  <input type="button" value="Page B">
  <input type="button" value="Page A">
</div>

Open in new window


jQuery
$('#myBtns input').click(function() {
  var newHref = "";
  switch ($(this).val()) {
    case "Page A":
      newHref = "Link 1"
      break;
    case "Page B":
      newHref = "Link 2"
      break;
    case "Page C":
      newHref = "Link 3"
      break;
  }
  $('#myTable a').attr('href',newHref);
  $('#myTable a').text(newHref);
});

Open in new window

0
 
LVL 42

Expert Comment

by:zephyr_hex
ID: 41834495
Did this answer your question?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now