jQuery: Replace strings with .each()

Posted by Warrantica on Stack Overflow See other posts from Stack Overflow or by Warrantica
Published on 2010-04-22T06:48:20Z Indexed on 2010/04/22 6:53 UTC
Read the original article Hit count: 140

Filed under:
|

I want a function that replace each li with an image. This is my code:

$(document).ready(function(){
var tmphref;
var tmpname;
var str = '<a href="' + tmphref + '"><img src="http://www.somesite.com/a/' + tmpname[1] + '/avatar-small.jpg /></a>';
$('#somediv li a').each(function(){
tmphref = $(this).attr("href");
tmpname = /http\:\/\/(\w+)\.somesite\.com\//.exec(tmphref);
$(this).parent().replaceWith(str);
});
});

The image is in this specific path: www.somesite.com/a/username/avatar-small.jpg
The code above doesn't work. Any ideas?

Thank you in advance.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about regex