Wednesday, January 5, 2011

Updating(Replace) anchor href values in a webpage

Using the jquery One can update attribute values of html elements in a simple steps .
The following jquery script will update the href value of all the anchor links those
 available in a web page to a static url http://www.tecrocks.com.

$('a[href]').attr('href', 'http://www.tecrocks.com');

This will be helpful for the situation like displaying the webpage content in a custom print preview page like so.
The following block will update all the href value in page without considering the element of the href value.

$('[href]').each(function () {
  $(this).attr('href', 'http://www.tecrocks.com');
});

Using *= filders with in [] we can filter the href url's.

No comments:

Post a Comment