Trafalgar D Law Trafalgar D Law - 1 year ago 195
Javascript Question

uncaught Syntax error, unrecognized expression option:contains

I have this

col model
from my jqgrid

colModel: [
{ name: 'rowId', index: 'rowId', hidden: true, width: 20 },
{ name: 'CompleteName', index: 'CompleteName', hidden: false, editable: true, sortable: false, width: 160, align: 'center' }

I have this code for the

onSelectRow: function (id) {
var objRowData = jQuery("#FAList").getRowData(id);
var CompleteName = objRowData.CompleteName;
$("#divFieldAssignment #EmpId option:contains (" + CompleteName + ")").attr('selected', 'selected');

But it gives me an error
uncaught Syntax error, unrecognized expression
but on my other code it is working fine. What's wrong with it?.

Answer Source

The problem is with the white space between contains and (

$("#divFieldAssignment #EmpId option:contains (" + CompleteName + ")").attr('selected', 'selected');

removing the space will fix the error.

White space in a CSS selector is a delimiter? between one part of a selector and the next

contains isn't valid

contains(whatever) is valid

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download