I have: var isPlatoonMember = ["Your", "Names", "Here"];
var posterName = $(".forum-threadview-post-poster .forum-threadview-post-poster-name").html();
if($.inArray(posterName, isPlatoonMember) > -1){ /* Do Stuff */ }
This works to see if any of the posters are on the page, but it will just apply the function inside the if statement to everyone. Is there a way to select only the people who has a name that matches one listed in the array?
BrainFooLong
Administrator
First of all, this code always get the first name of the first post.
Why?
1. You select all forum post elements.
2. .html() just output the first of the matched items (http://api.jquery.com/html/)
That should do the job. var isPlatoonMember = ["Your", "Names", "Here"];
$(".forum-threadview-post-poster .forum-threadview-post-poster-name").each(function(){
var posterName = $(this).text();
if($.inArray(posterName, isPlatoonMember) > -1){ /* Do Stuff */ }
});
Topicstarter
GameFreakBoy
Sort of. Now it will perform the action once to everybody for every match it finds. So if 3 people were found on the page. It would append 3 times to everyone.
Post edited 1 x times, last by
BrainFooLong
Administrator
BrainFooLong
Administrator
Well, than you must look at your selector what it select and make true that it doesn't happen when it's already happened.
But maybe it's just the " /* Do Stuff */" code that is wrong.
Post edited 1 x times, last by
GameFreakBoy
Topicstarter
GameFreakBoy
I found this solution while looking for alternative setups. This is one that I found, and it works perfectly. :) var isPlatoonMember = ["Your", "Names", "Here"];
var posterName = $.map(isPlatoonMember,function (item){
return ".forum-threadview-post-poster .forum-threadview-post-poster-name[href*=" + item + "]"}).join(",");
$(posterName).parent().children(".forum-threadview-post-tags").append(topLevel);}