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/"]');
    stripDepartmentLink(link1);
    stripDepartmentLink(link2);
});
 
function stripDepartmentLink(link) 
{
    $(link).after("<span>" + link.text() + "</span>");
    $(link).remove();
}


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.