JavaScript ID will not duplicate and using class doesn’t work either

I need my code colour highlights to function more than once on a page. I am using a JavaScript string but with ID but this doesn’t duplicate it, it only works for the first ID then the second and third don’t work. I have tried using class but this doesn’t work either.

w3CodeColor(document.getElementById("mycode"));
w3CodeColor(document.getElementsByClassName("mycode"));

Both of these don’t work

This is what I have tried already:

w3CodeColor(document.getElementsById("mycode"));
w3CodeColor(document.getElementsByClassName("mycode"));