javascript - Adding URL of a link pointing outside of a website next to the link text itself -
i'm reading 'javascript missing manual' , there script automatically adds url of link next link itself.
$('a[href^="http://"]').each(function(){ var href = $(this).attr('href'); href = href.replace('http://', ''); $['a'].after(' (' + href + ') '); }); // end each
the problem doesn't work @ all. please explain me what's wrong code?
change line
$['a'].after(' (' + href + ') ');
to
$('a').after(' (' + href + ') ');
$ should called function, not array.
although looking @ code, want instead:
$(this).after(' (' + href + ') ');
edit:
here total code:
$('a[href^="http://"]').each(function(){ var href = $(this).attr('href'); href = href.replace('http://', ''); $(this).after(' (' + href + ') '); }); // end each
javascript jquery manual
No comments:
Post a Comment