Set HTML attrbuites from SharePoint content type fields in page layouts


The Problem / Example : Need to put the “alt” attribute in the HTML “img” element from a content type field “Title” in a custom page layout and the content type fields represented as a SharePoint controls like that

SharePoint Field Value Control

You can do that simply by CSS/ JQuery :

1-Hide the SharePoint control that represent the field value using CSS and give the span container an ID “Ex: spanTitle” :

Hide SharePoint Field Value

2-Write the HTML “img” element with attribute “alt” empty and give it an id “Ex:exampleImage”  :

HTML img element3-Write these lines of JQuery that will fetch the value from the hidden span and put it to the “alt” attrbuite in the “img” element :
Fetch SharePoint Control Value And pass it to HTML attrbuite

Thanks !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s