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/

6
  • can you post the related html? Commented Nov 14, 2015 at 5:23
  • It is for a sharepoint list
    – KumarV
    Commented Nov 14, 2015 at 5:46
  • while debugging in browser it shows error "Uncaught Error: Syntax error, unrecognized expression: .ms-listviewtable tbody[selectablerows == ''] tr"
    – KumarV
    Commented Nov 14, 2015 at 5:49
  • you can take the html from browser Commented Nov 14, 2015 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 Commented Nov 14, 2015 at 6:04

2 Answers 2

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 and acknowledge you have read our privacy policy.

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