1

I have a small request for some help, how would I be able to call in two onClick calls within the same anchor tags?

I have the following:

onClick="wButton(this.id)"
onClick='window.location="#top"'

Appreciate the help!

1 Answers1

2

You cannot duplicate attributes in HTML. However, you can separate the statements within the onclick with a ; to execute them both:

onClick="wButton(this.id); window.location='#top'"

However you should note that the onclick attribute is very outdated. You should look in to using unobtrusive event handlers instead. In plain JS it would look like this:

document.querySelector('#yourElement').addEventListener('click', function() {
  wButton(this.id);
  window.location = '#top';
});

In jQuery it would look like this:

$('#yourElement').click(function() {
  wButton(this.id);
  window.location = '#top';
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339