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!
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!
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';
});