Jquery – Uncaught Error: Syntax error, unrecognized expression: #

asp.net, flexigrid, jquery

I am trying to obtain a cell's text value from a flexigrid.
However I keep getting that error.

This is my function for retrieving a specific cell's text(Flexigrid doesnt have "attr" it has "abbr" instead).

function getSelectedCopyDates() {    var arr = new Array();    debugger;    //for every row that has a checked checkbox    $("tr").has(".noteCheckBox:checked").each(function(i) {        if ($(this.id) !== "checkAllNotes") {            //push the value of column(FName, LName) into the array             arr.push($("#" + this.id + "> td[abbr='EventDate'] > div").text());        }    });    return arr;}

I only get that error when I click on "checkAllNotes"(main check box ). If I check a checkbox manually then everything works fine.

Here is my flexigrid layout:

$('#viewNotesGrid').flexigrid({    url: url,    dataType: 'json',    method: 'get',    colModel: [{        display: '<input type="checkbox" class="noteCheckBox" id="checkAllNotes" />',        name: 'checkBox',        width: 20,        sortable: false,        align: 'center',        process: showDescription    }, {        display: 'Date',        name: 'EventDate',        width: 80,        sortable: true,        align: 'center',        process: showDescription    },

Best Solution

1st problem is that $("tr").has(".noteCheckBox:checked") returns tr elements, not input checkboxes.

2nd problem: $(this.id) !== "value" will never work. You are creating jQuery object and comparing it with string. Should be this.id !== "value"

3rd problem: already explained in previous answer. If element doesn't seem to have id, then "#" + this.id + "> would result in "#>", and you actually want to compare id of special input field, not tr.

Making few assumptions here, but this might work:

function getSelectedCopyDates() {var arr = new Array();//for every row that has a checked checkbox$("tr .noteCheckBox:checked").each(function (i) {    if (this.id !== "checkAllNotes") {        var tr = $(this).parents("tr")[0]; // going back to parent tr        arr.push($(tr).find(" > td[abbr='EventDate'] > div").text());    }});return arr;}