SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page with some webparts on it, I want to get specific one (by name or ID) using client javascript. I try this code

var ctx=SP.ClientContext.get_current();
var web = ctx.get_web();
var site = ctx.get_site();
var theURL = window.location.pathname;
var oFile = web.getFileByServerRelativeUrl(theURL);
var limitedWebPartManager = oFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
var collWebPart = limitedWebPartManager.get_webParts();

How to get webpart by name or id after i get a collection? Maybe there is a easier way to do it?

share|improve this question
What is the intent of getting the webpart id? What do you want the code to do? This may help define he path needed to accomplish the goal. – spevilgenius Apr 16 '13 at 12:26
We have a webpart that displays a list. I want to get information from this web part, e.g. e-mails. – Dmitry T Apr 17 '13 at 14:39
If you are using client object model you should be able to use jQuery just as well. It may be easier! – spevilgenius Apr 18 '13 at 8:49
It has the answer i tested by id – user2098258 Jun 14 '13 at 5:46
This is a duplicate of:… Marking as duplicate. – Hugh Wood Oct 30 '13 at 9:47
up vote 2 down vote accepted

Once you execute the example you have above, you can (for example) get the title of all web parts on the page by executing this:

var i = collWebPart.get_count()
for (var j=0;j<i;j++)
    var webPart = collWebPart.get_item(j).get_webPart()



However, based on your comment above, it sounds like you might be looking for a value from a field from a listitem displayed in the list displayed by this webpart. If that is the case, you might want to try a more direct approach by getting the list, and then the list item, rather than getting the webpart.

share|improve this answer

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.