Comma in variable breaks template literal output

Solution 1:

Try label="${categoryTitle}" with quotes, because without quotes, it will generate

<optgroup label=Computers, Electronics, & Internet technology>

which is invalid, so the browser adds quotes around each word, and thinks Electronics is another attribute, leading to your problem.