jQuery Sizzle syntax error - uncaught expression
Asked Answered
B

1

5

I migrated from jQuery 1.6 (can't remember exact version) to jQuery 3.3.1 and I'm getting error in following code:

//datatable row click events
$('#@mainDatatableName tbody').on('click', 'tr', function () {
    checkForChange('#details-box', function () {
        //this will enable details refresh
        $('#detailsTab1 #Id').val(0); 

        debugger

        //force active detail to reload
        $('a[data-target=' + currentActiveTabContentId + ']').click();
    });
});

The syntax error goes as follows:

jquery-3.3.1.js:1541 Uncaught Error: Syntax error, unrecognized expression: a[data-target=#detailsTab1]
at Function.Sizzle.error (jquery-3.3.1.js:1541)
at Sizzle.tokenize (jquery-3.3.1.js:2193)
at Sizzle.select (jquery-3.3.1.js:2620)
at Function.Sizzle [as find] (jquery-3.3.1.js:845)
at jQuery.fn.init.find (jquery-3.3.1.js:2873)
at new jQuery.fn.init (jquery-3.3.1.js:2983)
at jQuery (jquery-3.3.1.js:139)
at UsersAdmin:1696
at checkForChange (domis.common.js:43)
at HTMLTableRowElement.<anonymous> (UsersAdmin:1693)

I don't understand why I'm getting this error. In the previous jQuery version this error didn't show up and the code worked. Was there a change in syntax in the new jQuery version or something else?

Brayton answered 17/8, 2018 at 7:13 Comment(0)
L
10

You need to have quotes on the data-target value in the selector

$('a[data-target="' + currentActiveTabContentId + '"]').click();
Lauderdale answered 17/8, 2018 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.