Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Replace contents of href="" with '#'

Tags:

jquery

I need a way of replacing the text contained within <a href="this text" using jQuery, I want to replace what ever text is held within quotes to a '#'.

Any suggestions?

like image 965
CLiown Avatar asked May 19 '10 14:05

CLiown


2 Answers

$('a').attr('href', '#');
like image 192
jAndy Avatar answered Sep 22 '22 06:09

jAndy


...

$(function(){
 $('a').attr('href', '#');
});

The ready handler should take care of changing the href of your links when the page loads.

If you have link(s) with some class or id set to them, you can simply do:

$(function(){
 $('a.link_class').attr('href', '#');
 // $('#some_id').attr('href', '#'); // for id
});

If you want to do it with some button click, etc, you can do like:

$('#button_id').click(function(){
  $('a').attr('href', '#');
});
like image 42
Sarfraz Avatar answered Sep 18 '22 06:09

Sarfraz