Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Do you know how to get the current web part Id with the javascript client OM API ?

Or an idea for a work-around ?


share|improve this question

1 Answer 1

Your Web Part will have an element attribute called webpartid so you can use this to select all Web Parts, like this (jQuery):


To select your own specific Web Part you could add something specific in the markup you can use to select it, for example an empty/hidden element with a specific class, like <span class="my-hack"></span>, then your Web Part can be selected like this (jQuery):

 // or
// or
share|improve this answer
thx ! Do you know a way to access a specific instance (in the case where there are more than one instances of this web part in a page) ? –  dino Sep 27 '12 at 8:04
That is what the .my-hack is for, something within the markup that tells you it is your Web Part. You could also use the Title, but this is dangerous as the title can be removed (Chrome Frame Type). In theory: $('[webpartid]:has(.my-hack)').each(function(){ var $myWP = $(this); ... }); –  eirikb Sep 27 '12 at 8:08
it didn't worked for me, I had to get it with : $('.someClass').parents('.ms-WPBody').attr('webpartid'); –  dino Sep 27 '12 at 12:58
The one I used with .closest should work, it reads as > "recursive parent of your element (.my-hack) with attribute 'webpartid' defined" –  eirikb Sep 27 '12 at 13:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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