0

l have got a series of menus.

What l want to do is change the background-color of the link onclick.

What l have done use jquery like this

jQuery('.menu a').click(function(){
     var clz = jQuery(this).attr('id');
     jQuery(this).attr('class','active'+clz);
  })

This is not work.The code needs to work on mobile phones

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MartinRinehart
0

Using 'a:visited' you can set the style for visited links:

/* CSS */
a:visited { background-color: red; }

Is that enough?

0

Thank you for the reply.

What l need howwever is when u click the background changes something like the iphone otouchstart trigger

0

Then you need to write an event handler in JS. Three steps.

1) give the trigger an id, use it to get the element
2) write a function that handles the event
3) assign the function to the trigger element's 'onclick'

var trigger_ref = document.getElementById( 'trigger_element' );

function handle_trig_click() {
    /* code here to respond to the click. 'this' is the trigger element. */
}

trigger_ref.onclick = handle_trig_click; // NOTE: NO PARENS!

I always start the onclick function with just an alert:

function handle_trig_click() {
    alert( 'Hey! I'm in handle_trig_click()!' );
}

That way you don't waste hours trying to debug a function that isn't called.

Good luck.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.