Using JQuery to remove Linked List Items hyperlinks.

A client of mine recently raised a concern about the linked list items that are used within SharePoint. In the display list view, they show up as hyperlinks to the linked item. All well and good, you can click on these links to see the full item, however there is no easy way to return as when you click on close you are sent to the default view for the list the linked item belongs to.. (Still with me?)

We discussed several ways around this, but the feeling from the client was that they didn’t want to see these links anyway, so removing them would be the best solution. (I did suggest creating a whole new field type with the option to turn off the Hyperlink in the display render, but they felt that was overkill)

Having played with JQuery, I was pretty certain that we could override the default behaviour using a simpler jQuery selector.. But what do we select?

Well the Linked List items very handily all have the term RootFolder=* in their URL. No other link in SharePoint appears to have this and certainly my testing hasn’t thrown up any errors yet!

So, how do we remove this link in jQuery? Well the trick is to return a collection of A tags that have an Href containing the pattern “RootFolder=*”. Once we have this, we simply add a sibling node using the .After() function to create a new span tag, and then copy the previous tags text content into the new tag, before hiding the A tag using .Remove()

It sounds very simple and it is, but as I found during this exercise, the secret is getting your selectors spot on and making sure the code is firing properly!

Paul.

Note: You will need to have downloaded the JQuery library and registered it in the masterpage, along with the code below (Which can either go in a Content Editor Web Part, or be placed in the Masterpage itself if you want to affect every page.)




Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.