0

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?

3
  • can you share the html sample of the elements also Commented Feb 3, 2014 at 10:35
  • Where do you want to add the html if it matches? Commented Feb 3, 2014 at 10:43
  • Just a simple prepend. I had it working but then I got two icons in one place <.< And now its broken again Commented Feb 3, 2014 at 13:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

dropbox.com/s/ljqi470tpt5cf4e/… it's not really working =/ I had it working with your previous answer, but then I had two icons in one place
dropbox.com/s/5twjwjd6jw5c2fl/… As you can see, two icons in one place.
@user3227070 in the loaded html also you are using $ directly to refer jQuery change them also
@user3227070 please edit the fiddle I shared to recreate the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.