curioussam
curioussam

Reputation: 449

Clicking link in JavaScript

I have an anchor tag on all my pages:

<a id='signout' href='//somelocation'>SignOut</a>

and I have a JavaScript file that is available to all pages. There is a function that is called and attached to 'click' , 'touch' and 'key press' handler where I am trying to click the link. Something like:

document.addEventListener('click' function(e){
   var signoff = document.getElementById('signout');
   location = signoff.href;  
}

This should just click the anchor tag whenever there is a click event but is not working.

Upvotes: 0

Views: 83

Answers (1)

Lucas
Lucas

Reputation: 362

Some syntax corrections got it working for me:

document.addEventListener('click', function(e) {
   var signoff = document.getElementById('signout');
   location = signoff.href;
});

http://jsfiddle.net/jjGeJ/

Upvotes: 1

Related Questions