That won't work in the head because the button doesn't exist yet. If the page already uses jQuery, this should work:
Code:
<script type="text/javascript">
jQuery(function($){
$('#Button').click(function(e){
alert('clicked');
return false;
});
});
</script>
I say should, because if the CMS has already assigned it an on click function, that may still fire and may fire first. And that may vary by browser.
A rough equivalent if jQuery isn't on the page would be:
Code:
<script type="text/javascript">
if (window.addEventListener){
window.addEventListener('load', function(){
document.getElementById('Button').addEventListener('click', function(e){alert('clicked');e.preventDefault();}, true);
}, false);
}
else if (window.attachEvent){
window.attachEvent('onload', function(){
document.getElementById('Button').attachEvent('onclick', function(){alert('clicked');event.returnValue = false;});
});
}
</script>
But again, if the CMS has already assigned an on click event to it, that may take precedence. And that may vary by browser.
The browser cache may need to be cleared and/or the page refreshed to see changes.
If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
Bookmarks