Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Sizzle syntax error - uncaught expression

Tags:

jquery

sizzle

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?

like image 537
Bernard Polman Avatar asked Jan 02 '23 23:01

Bernard Polman


1 Answers

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

$('a[data-target="' + currentActiveTabContentId + '"]').click();
like image 51
void Avatar answered Jan 05 '23 16:01

void