tags:

views:

39

answers:

2

Hi I would like to replace all href and action attributes on a page with href="#" and action="#". Could someone point out where i am going wrong;

$(document).ready(function(){
var contents = $("body").html();
contents.replace( /href=[\"'][^'\"]*[\"']/g, 'href="#"' );
contents.replace( /action=[\"'][^'\"]*[\"']/g, 'action="#"' );
});

I would also like to do this without the use of jQuery but not sure how.

+5  A: 

Why don't you try something like :

$('a').attr('href','#');
$('form').attr('action','#');
Soufiane Hassou
A: 
$(document).ready(function(){
    $("a, area, form").each(function(){
        if (typeof $(this).attr("href") != 'undefined') {
            $(this).attr("href", "#");
        }else if(typeof $(this).attr("action") != 'undefined') {
            $(this).attr("action", "#");
        }
    });
});

I added a tick to Soufiane Hassou answer as I found the answer via his comment, thanks

Phil Jackson