Uncaught Error: Syntax error, unrecognized expression
Hello there!
For last two day's I'm trying to figure out what is causing the syntax error and would appreciate any help.
- $("[name='Item.Index']").each(function () {
var index = $(this).val();
console.log("index: " + index); //index value is 0
console.log($("[name='EI[0].ItemType']").val()); //outputs correct value
console.log($("[id='EI_0__ItemType']").val()); //outputs correct value
var t = "\"[id='EI_" + index + "__ItemType']\"";
console.log("t: " + t); //output is t: "[id='EI_0__ItemType']"
console.log($(t).val());
- });
The last line console.log($(t).val()); is giving an error:
Uncaught Error: Syntax error, unrecognized expression: "[id='EI_0__ItemType']"
at Function.Sizzle.error (jquery-3.5.1.js:1677)
at Sizzle.tokenize (jquery-3.5.1.js:2377)
at Sizzle.select (jquery-3.5.1.js:2838)
at Function.Sizzle [as find] (jquery-3.5.1.js:894)
at jQuery.fn.init.find (jquery-3.5.1.js:3095)
at new jQuery.fn.init (jquery-3.5.1.js:3205)
at jQuery (jquery-3.5.1.js:157)
at HTMLInputElement.<anonymous> (Create:381)
at Function.each (jquery-3.5.1.js:381)
at jQuery.fn.init.each (jquery-3.5.1.js:203)
Any clues?
Joe