Reputation: 652
With some help , i was able to replace some text with an image for each member
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Fighting Moose Knuckles', '<img src="http://larryvasta.com/football/img/icons/Moose_Icon.png" />') );
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Grundle Goblins', '<img src="http://larryvasta.com/football/img/icons/Goblins_Icon.png" />') );
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Commissioner', '<img src="http://larryvasta.com/football/img/icons/Commish_Icon.png" />') );
I need to add a link to each image to direct them to their profile page.
Upvotes: 0
Views: 46
Reputation: 10045
How about introducing a bit of reusability.
function replaceTextWithImage($element, str, imageSrc){
$element.html($element.html()
.replace(str, '<a href="#"><img src="'+ imageSrc +'"></a>'));
}
var $chatScroll = $("#chatscroll");
replaceTextWithImage($chatScroll, 'Fighting Moose Knuckles','http://larryvasta.com/football/img/icons/Moose_Icon.png');
replaceTextWithImage($chatScroll, 'Grundle Goblins','http://larryvasta.com/football/img/icons/Goblins_Icon.png');
replaceTextWithImage($chatScroll, 'Commissioner','http://larryvasta.com/football/img/icons/Commish_Icon.png');
Upvotes: 0
Reputation: 3041
How about just add the links to your existing code? See the <a href="#">
in the example below:
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Fighting Moose Knuckles', '<a href="#"><img src="http://larryvasta.com/football/img/icons/Moose_Icon.png" /></a>') );
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Grundle Goblins', '<a href="#"><img src="http://larryvasta.com/football/img/icons/Goblins_Icon.png" /></a>') );
$( "#chatscroll" ).html( $( "#chatscroll" ).html().replace('Commissioner', '<a href="#"><img src="http://larryvasta.com/football/img/icons/Commish_Icon.png" /></a>') );
Upvotes: 2
Reputation: 67207
Try to use .wrap()
at this context,
$('#chatscroll img').wrap('<a href="yourLink.com"></a>');
Upvotes: 1