3 Replies Latest reply on Nov 8, 2016 5:33 AM by try67

    Do I really need seven copies of this code?

    higgsyd Level 1



      On the above page I have seven buttons.  When you hover over any of them the text changes to white and the user is directed to the appropriate page.  A simple implementation of a rollover image.


      You can see the javascript if you use View Page Source and then click the myscript.js link on line 6


      Each img has an ID allocated to it which links to the code which, when the button is hovered over, replaces the image with the over image with the white text, then puts the old image back when the hover is out.


      But I have found I must customise the code for each button.  Specifically, I have to change the names of the images, variable names and the name of the selector targetting each button.  So I end up with seven copies of the same code!  Can it perhaps be changed to a function which accepts these changes as parameters?


      many thanks in anticipation