0

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?

Thanks.

2 Answers 2

1

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

<div id="mySpan"></div>
<script>
    $("#mySpan").closest("div[WebPartID]").attr("WebPartID")
</script>
0
0

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

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

Should result in:

<span>
  3766612-68c3-46cf-bb31-f0725c7f71f
</span>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.