The magical IID attribute in SharePoint List Views

SharePoint is full of undocumented and largely unknown hints and tricks you can leverage when you build solutions. Often when I am F12-ing through a site, I come across these little gems and do my best to remember them for future reference.

One such bit that has proven itself useful to me a couple of times is the IID attribute, found on every tr element in every SharePoint List View.

iid screenshot

As you can see, the iid attribute is composed of three comma-separated values. Here’s my best swag as to what these mean:
• Context ID. This is the value of the ctx.ctxId variable in the SharePoint-generated JavaScript included with the List View Web Part.
• Item ID. This is the list item’s ID.
• objectType. This corresponds to the FSObjType, meaning its value will be zero for a list item and one for a folder.

The Item ID is the important value here, at least in my case. I was looking for a way to fetch the ID of the currently selected list item, and the iid attribute, along with the CSS class of s4-itm-selected, gave me what I was looking for. By doing a JavaScript split in the iid attribute and taking the second element of the returned array, I was able to get that ID.

So the jQuery for getting the currently selected list item’s ID is:
var id = $(“tr.s4-itm-selected”).attr(“iid”).split(“,”)[1];

I had to incorporate some checks to make sure there was only one item selected, but this is the jist of the code.


5 thoughts on “The magical IID attribute in SharePoint List Views

  1. This bit of code seems like it will fail when there is more than one selected item. You’ll really only get the first selected item.
    To get all of the selected items, you’ll want to use .each().

    var IDs = [];
    $(“tr.s4-itm-selected”).each(function() {
    IDs.push( $(this).attr(“iid”).split(“,”)[1] ); //Or process id’s right here w/o the array

    and then…
    IDs.forEach(function() { //process });

    However, I’d opt for the Microsoft built method described here:
    Here’s some example codez:
    ExecuteOrDelayUntilScriptLoaded(function() { console.dir( SP.ListOperation.Selection.getSelectedItems() ); }, “sp.js”);
    This seems like a much better way to go other than relying on jQuery.



  2. Pingback: Curia Damiano blog | SharePoint: iid attribute of a List View web part

    • You’ll have to check that the user has only selected one item. You can do this using the length property in jQuery:
      var howMany = $(“tr.s4-itm-selected”).length;

      I would check out iOnline247’s response here in the comments. He sheds some light on the issue of many multiple items selected, and provides a better solution as well.

      Good luck!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s