HTML img onclick Javascript
Developers also take care about accessibility.
Do not use onClick
on images without defining the ARIA role.
Non-interactive HTML elements and non-interactive ARIA roles indicate content and containers in the user interface. A non-interactive element does not support event handlers (mouse and key handlers).
The developer and designers are responsible for providing the expected behavior of an element that the role suggests it would have: focusability and key press support. More info see WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets.
tldr; this is how it should be done:
<img
src="pond1.jpg"
alt="pic id code"
onClick="window.open(this.src)"
role="button"
tabIndex="0"
/>
here you go.
<img src="https://i.imgur.com/7KpCS0Y.jpg" onclick="window.open(this.src)">
This might work for you...
<script type="text/javascript">
function image(img) {
var src = img.src;
window.open(src);
}
</script>
<img src="pond1.jpg" height="150" size="150" alt="Johnson Pond" onclick="image(this)">