Reputation: 786
I have an object like this:
obj {"name" : "html"
"name2" : "html"
"name3" : "html"}
I want to check every a element on a page, and if the object name matches the text in the a element, insert the html for that name.
How can I do this?
Html:
<div id="paged_view_content">
<div class="vis_item" align="center">
<a href="/game.php? t=487615717&village=22979&mode=combined&group=5043&screen=overview_villages" class="group_tooltip">[00 ATT-BUNK]</a>
<a href="/game.php? t=487615717&village=22979&mode=combined&group=1276&screen=overview_villages" class="group_tooltip">[01 ATT-NOR]</a></div></div>
My "name"s will exactly match names like [01 ATT-NOR] :)
I can check the names with Indexof, but how do I check for each name in the object, and thenn add the html if it matches?
Upvotes: 0
Views: 50
Reputation: 388316
Try
$('#paged_view_content a').text(function (i, text) {
text = $.trim(text);
var key = text.substring(1, text.length - 1);
return obj[key]
})
Demo: Fiddle
Upvotes: 1