0

I have hundreds of link variables.

var aa = "http://site1.com";
var bb = "http://site2.com";
var cc = "http://site3.com"; 

How can I implement an onclick function that when you click for example "aa" id font, it goes to aa link ?

<font id="aa">site1</font>
<font id="bb">site1</font>
<font id="cc">site1</font>
4
  • 4
    Don't. Use an <a> with an href. Why would you want to make <font> elements clickable, and thus make your page unusable for keyboard users who for whatever reason can't use a mouse or other pointing device? Commented Aug 7, 2013 at 0:25
  • For spesific reasons. But thats not the case. Commented Aug 7, 2013 at 0:28
  • 1
    Assuming you have a good reason for what you're trying to do, what, actually, have you tried already? Commented Aug 7, 2013 at 0:32
  • <font> is a silly tag to be using in the first place. Use an <a> tag or people will hate your website. Commented Aug 7, 2013 at 17:01

1 Answer 1

1

You could do something like this but you really should just use a tags if possible ...

<div id="myClickContainer">
  <font id="aa"> ... </font>
   .
   .
   .
</div>

<script> 
  var links = {aa: 'http://site1.com', ... }
  $("#myclickContainer").click(function(event) {
    location.href = links[event.target.id] 
  });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.