skip to Main Content

I am having trouble getting my JavaScript code to change the CSS style of my article element. I have this in the opening tag for my article element:
”’

<img id="n1" onmouseover="visible('c1')" src="img/musicnote1.png" alt="Music Note">

”’
and then at the bottom of my body section I have my script tag:
”’

<script>
    function visible(a){
        document.getElementById(a).style.display = initial;
        document.getElementById('default').style.display = none;
    }
</script>

”’
I am trying to make the ‘c1’ article appear and the ‘default’ article disappear when the user hovers over the image. Neither of these actions are working

2

Answers


  1. It seems you need to assign strings as attributes:

    <script>
        function visible(a){
            document.getElementById(a).style.display = 'initial';
            document.getElementById('default').style.display = 'none';
        }
    </script>
    
    Login or Signup to reply.
  2.   <img id="n1" onmouseover="visible('c1')" src="img/musicnote1.png" alt="Music Note">
    
    <script>
        function visible(a){
            document.getElementById(a).style.display = 'block';
            document.getElementById('default').style.display = 'none';
        }
    </script>
    
    try this 
    maybe it will help
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search