How to disable all links using jQuery

To disable all links using jQuery you cna use the snippet below.

Samples

jQuery Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to style a link by filetype in CSS

To style a link by filetype in CSS you can use the following snippet.

Sample CSS

a[href$=".exe"] { background: url(icons/exe.png) left center no-repeat; padding-left: 50px; }
a[href$=".rar"] { background: url(icons/rar.png) left center no-repeat; padding-left: 50px; }
a[href$=".doc"] { background: url(icons/doc.png) left center no-repeat; padding-left: 50px; }
a[href$=".pdf"] { background: url(icons/pdf.png) left center no-repeat; padding-left: 50px; }
a[href$=".zip"] { background: url(icons/zip.png) left center no-repeat; padding-left: 50px; }
a[href$=".html"] { background: url(icons/link.png) left center no-repeat; padding-left: 50px; }

Please rate this snippet

How to change the href for a hyperlink using jQuery

To change the href for a hyperlink using jQuery you can use the following snippet.
The following example will change every href to http://codesnippets.fesslersoft.de.

Sample jQuery

$("a").attr("href", "http://codesnippets.fesslersoft.de/")

if you want to change every href pointing to http://codesnippets.fesslersoft.de with a href pointing to http://codesnippets.fesslersoft.de/change-the-href-for-a-hyperlink you can use the following snippet.

Sample jQuery

$("a[href^='http://codesnippets.fesslersoft.de/']")
   .each(function()
   { 
      this.href = this.href.replace("http://codesnippets.fesslersoft.de/", "http://codesnippets.fesslersoft.de/change-the-href-for-a-hyperlink");
   });

Please rate this snippet

How to do a HTTP redirect using Javascript or jQuery

To do a HTTP redirect using Javascript or jQuery you can use the window.location.href or the window.location.replace property.

Sample Javascript href

window.location.replace("http://codesnippets.fesslersoft.de");

Sample Javascript replace

window.location.href = "http://codesnippets.fesslersoft.de";

difference of these two

you should use replace if you want to create a http redirect and href if you want to simulate a click.

 

You can also do this in jQuery but i personally prefer the methods shown above because there is no need to use jQuery for a http redirect.

Sample jQuery

var newUrl = "http://codesnippets.fesslersoft.de";    
$(location).attr('href',newUrl);

for more information see W3Schools: Location href Property, Location replace() Method

Please rate this snippet