Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Conditional Link URL - Easy Question

Posted on 2016-09-27
4
Medium Priority
?
80 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 29

Expert Comment

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

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 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 44

Expert Comment

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

Featured Post

Google Certified Professional - Cloud Architect

This course (1 of 3) is designed to help students who are interested in Google Cloud Platform (GCP) to become familiar with the platform, navigate the console and learn its capabilities. It will also prepare students for the Google Cloud Architect certification exam.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

722 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