Thursday 4 July 2013

Strip Lookup Field Link

When you display a lookup field on a page, SharePoint automatically creates a link to that list item, the simplest way to remove these links is just to run JavaScript using jquery to clear them out

$(document).ready(function () 
    var link1 = $('a[href*="/Lists/JobPostingDepartment/"]');
    var link2 = $('a[href*="/PolicyProcedure/Lists/ccwTypes/"]');
function stripDepartmentLink(link) 
    $(link).after("<span>" + link.text() + "</span>");

basically what $('a[href*="/Lists/JobPostingDepartment/"]'); says is, 
grab all the anchors that have an href attribute with the value in double quotes 
somewhere in the attribute.