Answer:
Here is a JavaScript code snippet that allows you to apply styling dynamically without the need for jQuery:
This approach grants you flexibility in styling elements using JavaScript, and it is also more efficient than using jQuery.
<script type="text/javascript">
function addClass()
{
document.getElementById("apple").className += " secondname";
}
function removeClass()
{
//replaces all classes with initial class
document.getElementById("apple").className = "name";
}
window.onload = function()
{
document.getElementById("apple").addEventListener( 'mouseover' , addClass );
document.getElementById("apple").addEventListener( 'mouseout' , removeClass );
}
</script>
...
<img src="img/nex2.jpeg" id="apple" class="name">
It's important to note that utilizing CSS remains the most efficient method:
img.name:hover
{
//apply all styles from class name secondname
}
By following this technique, you can streamline your styling process by using just one class instead of two.
Feel free to explore different styling options according to your preference.