Solved

Conditional Link URL - Easy Question

Posted on 2016-09-27
4
70 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

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

Accepted Solution

by:
zephyr_hex (Megan) 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 43

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
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 get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

696 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