various shenanigans.

JQuery – Get Value of DIV with Custom Attribute

I have a ProjectServer with a custom field (Project Status Slide) where users have a URL for an image.

I needed to retrieve the URL from the custom field and display it inline on the ProjectDetails.aspx page

<div GUID=”xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx”>http://myserver/PWA/Pictures/Slide1.png</div>

The source of the custom field resembles the above.

I put a Content Editor Web Part at the bottom of the ProjectDetails.aspx page with the following script.

<img id="pss" src="/PWA/Project%20Detail%20Pages/" alt=""/> -- Placeholder for the Slide.
<script src="/PWA/Project%20Detail%20Pages/jquery.js" type="text/javascript"></script> -- Jquery
  <script>
$(document).ready(function(){
var myDiv = $("div[GUID='xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx']"); -- Look for DIV with Custom Attribute
var URL1 = $(myDiv).text(); -- Get the URL between that DIV
URL1 = URL1.replace("http:", "https:"); -- Just in case some used HTTP
// alert(URL1); -- for debug
 $('#pss').attr('src', URL1); - Replace my image src above with the Slide URL
 });</script>
Close Bitnami banner
Bitnami