In sharepoint 2013, I have a content editor web part. I have javascript code in it. I want to get a GUID. I want to get the GUID of the instance of the web part. So if I had 2 content editor webparts they should have unique identifiers each. No other content editor web part (even on another page) should have that same GUID.
I was looking at the DOM explorer in dev tools, and see on the web part there is a tag with class ms-WPBody
and attribute webpartid="7722f3d5-e8da-4b3b-acc4-3bf3e6f9aba7"
(for example). It seems to be different per instance of this web part on the same page too.
If I put the javascript code in the web part (linked to a file option too). I am thinking of doing something like, using jquery's nearest function to get the closest parent div.ws-WPBody
and then grabbing the webpartid value.
Is this an ok way, or is there any issues or better ways?
Thanks