Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a hyperlink from linking

Tags:

css

asp.net

Is it possible to prevent an asp.net Hyperlink control from linking, i.e. so that it appears as a label, without actually having to replace the control with a label? Maybe using CSS or setting an attribute?

I know that marking it as disabled works but then it gets displayed differently (greyed out).

To clarify my point, I have a list of user names at the top of my page which are built dynamically using a user control. Most of the time these names are linkable to an email page. However if the user has been disabled the name is displayed in grey but currently still links to the email page. I want these disabled users to not link.

I know that really I should be replacing them with a label but this does not seem quite as elegant as just removing the linking ability usings CSS say (if thats possible). They are already displayed in a different colour so its obvious that they are disabled users. I just need to switch off the link.

like image 989
Simon Keep Avatar asked Sep 08 '08 09:09

Simon Keep


People also ask

How do you unlink a hyperlink?

To remove a hyperlink but keep the text, right-click the hyperlink and click Remove Hyperlink. To remove the hyperlink completely, select it and then press Delete.

How do I stop a hyperlink from continuing?

If you've already got a page full of links, nuke them all at once. Just select all the text in the document (press Ctrl+A) and then press Ctrl+Shift+F9. Finally, you can remove links selectively. If you want to remove a link and leave the text intact, right-click the link and choose Remove Hyperlink from the menu.

How do you unlink a link in HTML?

Just select the text where you want to remove the links, click the Insert/edit link, then leaving all fields empty click Ok.


1 Answers

This sounds like a job for JQuery. Just give a specific class name to all of the HyperLink controls that you want the URLs removed and then apply the following JQuery snippet to the bottom of your page:

$(document).ready(function() {
    $('a.NoLink').removeAttr('href')
});

All of the HyperLink controls with the class name "NoLink" will automatically have all of their URLs removed and the link will appear to be nothing more than text.

A single line of JQuery can solve your problem.

like image 84
NakedBrunch Avatar answered Sep 24 '22 18:09

NakedBrunch