I am trying to compare the values of two elements, and if they share that value, execute a .css() modifier upon one of them. The issue is that some of my comparing elements have values in a comma separated list:
normal values: "400", "500"
comma’d values "600, 602" "502, 504"
My jQuery is as follows:
jQuery('#container1 > div[booth-number="{Booth Assignments}"]').css('background-color','white')
as you can see I’m using a merge tag to indicate the booths that i’d like to have their background color modified with.
I was also trying something like a forEach loop:
const booths = [{Booth Assignments}]
booths.forEach(jQuery('container1 > div[booth-number=jQuery(this)]').css('background-color', 'white')
which does not seem to work either. could really use some help here!
2
Answers
Your foreach syntax is incorrect.
First, you can take the array and join it with a comma, replace the spaces, then split it on the comma. This will allow you to loop through the items.
Next, I’m using a data attribute since booth-number isn’t valid.
Since you are using jquery, I’m also just using $.each