I have added a content editor web part in a SharePoint web part page. I have some java script code logic which renders some HTML and I have added that script to content editor web part Content Link.

Is it possible to read the current content editor web part Id or any unique property of the current content editor web part from the script being linked in Content Link?


2 Answers 2


Add this to the file linked using Content Link to show WebPart ID. Requires jQuery.

<div id="mySpan"></div>

NOT TESTED - pulled it from old code

Without jQuery and not requiring a 'marker' DIV to know where your code is

Since you can add events to an IMG tag

  <img onerror="
                var el=this;
                while (!(el.getAttribute(dataAttr) || el===document.body))el=el.parentNode;
                var id=el.getAttribute(dataAttr);

Should result in:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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