2

I have got the below code to get the ID's of all selected items of a list. This code worked for me when I used it for other list but now when I am using for another list, this code is not getting the ID values.

 $(".ms-listviewtable tbody[selectablerows == ''] tr").each(function (i, row) {
            var $row = $(row);

            if ($row.find("td[class*='ms-cellStyleNonEditable ms-vb-itmcbx ms-vb-imgFirstCell']").children('div.s4-itm-cbx.s4-itm-imgCbx').attr("aria-checked")=="true")
            {


                $selected = $row.find("td[class*='ms-cellStyleNonEditable ms-vb-itmcbx ms-vb-imgFirstCell']").children('div.s4-itm-cbx.s4-itm-imgCbx');
                $Contextid = $selected.context.id;
                $id = $Contextid.slice($Contextid.indexOf(',') + 1, $Contextid.lastIndexOf(','));
                alert($id);

                    array[idCount]=$id;
                    idCount=idCount+1;
}           
        });

it shows error

Uncaught Error: Syntax error, unrecognized expression: .ms-listviewtable tbody[selectablerows == ''] tr

while debugging it only shows that the array value is 0. But if I select two items, it should show me the ID's of both the list items.

HTML Code- http://jsfiddle.net/mag4zj0v/

  • can you post the related html? – Atish Dipongkor - MVP Nov 14 '15 at 5:23
  • It is for a sharepoint list – KumarV Nov 14 '15 at 5:46
  • while debugging in browser it shows error "Uncaught Error: Syntax error, unrecognized expression: .ms-listviewtable tbody[selectablerows == ''] tr" – KumarV Nov 14 '15 at 5:49
  • you can take the html from browser – Atish Dipongkor - MVP Nov 14 '15 at 5:51
  • 1
    just take the html under this .ms-listviewtable tbody[selectablerows == ''] tr selector. If it is still big then paste in jsbin or jsfiddle and then give the link here – Atish Dipongkor - MVP Nov 14 '15 at 6:04
0
$(".ms-listviewtable tbody[selectablerows != ''] tr").each(function (i, row) {
            var $row = $(row);

            if ($row.find("td[class*='ms-cellStyleNonEditable ms-vb-itmcbx ms-vb-imgFirstCell']").children('div.s4-itm-cbx.s4-itm-imgCbx').attr("aria-checked")=="true")
            {


                $selected = $row.find("td[class*='ms-cellStyleNonEditable ms-vb-itmcbx ms-vb-imgFirstCell']").children('div.s4-itm-cbx.s4-itm-imgCbx');
                $Contextid = $selected.context.id;
                $id = $Contextid.slice($Contextid.indexOf(',') + 1, $Contextid.lastIndexOf(','));
                alert($id);

}           
        });

This worked for me, I dont knw why it worked with same == for other site and in this site it worked with !=

0

I believe your selector is actually incorrect.

tbody[selectablerows == '']

Should be

tbody[selectablerows = '']

See the following reference about jQuery selectors W3Schools

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.