JavaScript for WordPress Forums Vanilla JavaScript What am I doing wrong here? Reply To: What am I doing wrong here?


What are you trying to accomplish? That will determine how someone responds to your question. A couple things though:

getElementsByClassName only needs a class name, not a selector (i.e. ‘gallery-icon’ not ‘.gallery-icon’, note the dot)

getElementsByClassName returns an array, so either you need to select an item from that array (e.g. content = getElementsByClassName('gallery-icon')[0] and then set that innerHTML, or loop through each item and set the innerHTML for each pass, but it depends on what you’re trying to do

Also, all your innerHTML += lines should end in a semicolon, not a period