Solved

Conditional Link URL - Easy Question

Posted on 2016-09-27
4
72 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 28

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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 …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

728 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