I'm working on some DOM scraping in SP and I want to tighten up my logic around web-parts. Namely, is it safe to say that anything with a attribute of 'webpartid' is a webpart?

Some sample environments I've been in have lots of elements with this attribute that look empty/useless.

Alternatively, can I say that anything with an id = 'webpart' is a webpart? Those counts don't add up btw...

EDIT: or, is it any element with both of those attribute criteria?


The following assumes SP2010. You would be 100% safe assuming that a DIV element with a webpartid attribute is the body container for the web part. If you want to find the starting point for a webpart (i.e. the chrome), look for table elements with a class attribute of s4-wpTopTable.

  • 1
    You can also narrow down the correct element by using the developer tools built in to IE (or Chrome as well). Hit F12 to bring up the dev window. Then select the pointer icon (or hit Ctrl+B while in the dev window). You can then use your mouse to select the element on the html page. A blue window is displayed around the 'selected' DOM element. Click the mouse button and the dev window navigates to the selected DOM element.
    – Rich Ross
    Jul 28 '11 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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