Uncaught DOMException: String contains an invalid character. Where is it?

Hi, all. I’ve been looking through my code, trying to find where the stray character is, but I just cannot find it. Here’s to hoping a fresh pair of eyes will help! The editor says the error’s in the line: var newDiv = document.createElement(stationName);

var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);

var primaryTheme = document.getElementsByName('primary_theme');
var stationName = document.getElementsByName('addTitle');

var seconds = 0, minutes = 0, hours = 0, stopwatchOn = false;
var stations = [];

function makeStation() {
  var length = primaryTheme.length;
  for (var i = 0; i < length; i++) {
    if(stationName !== '') {

      var newDiv = document.createElement(stationName);
      newDiv.id = stationName;
      newDiv.className = stationsBox;
      stations.push(newDiv);

var stationName = document.getElementsByName('addTitle');

What is stationName set to?

document.createElement(stationName);

What type of argument does createElement take?

Oh, I see! The element ‘addtitle’ was a text input box, but I didn’t realize you had to add a .value in order to access the actual string inside it. Thank you so much!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.