user3482256
user3482256

Reputation: 9

Chrome giving me an error on the JS console: "Uncaught InvalidCharacterError: The string contains invalid characters."

It is pointing me to line

var T = document.createElement("table id=""+tableID+""");

in which I was trying to create a table element with a particular ID. Any idea what happened? I thought I made a proper escape sequence.

Upvotes: 0

Views: 848

Answers (2)

epascarello
epascarello

Reputation: 207511

Some IE versions let you have a full tag inside of of document.create, but standards following browsers only accept the tag name. To set the id, you can either set the attribute directly or use setAttribute.

var T = document.createElement("table");
T.id=tableID;

or

var T = document.createElement("table");
T.setAttribute("id", tableID);

Upvotes: 3

pawel
pawel

Reputation: 36965

The invalid character here is space. document.createElement only takes the element name as the argument, and element names can not contain spaces. So you should create the elemnt first, then set its attributes/properties.

var T = document.createElement('table');
T.id = tableID

Upvotes: 1

Related Questions