I'm using this script:
<html>
<script>
function hover(element) {
element.setAttribute('src', 'http://dummyimage.com/100x100/eb00eb/fff');
}
function unhover(element) {
element.setAttribute('src', 'http://dummyimage.com/100x100/000/fff');
}
</script>
<img id="my-img" src="http://dummyimage.com/100x100/000/fff" onmouseover="hover(this);" onmouseout="unhover(this);" />
</html>
I will change the image source but I want to fix width to 120px. How can I do this?
Using the style attribute
element.style.width = '120px';
and you can also add alot more styling with the same attribute like padding, margin, font-size, ..etc