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.
As you can see, the iid attribute is composed of three comma-separated values. Here’s my best swag as to what these mean:
• 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.
So the jQuery for getting the currently selected list item’s ID is:
var id = $(“tr.s4-itm-selected”).attr(“iid”).split(“,”);
I had to incorporate some checks to make sure there was only one item selected, but this is the jist of the code.