1

So I know how to do something like this, but I have multiple elements that my .each(function() is running on, I need to make sure only .modules that contain spans with "Open 24 hours" trigger the change of the div to "ALWAYS OPEN" and I can't figure out what I am doing wrong

if (thisTimeSet === 'Open 24 hours'){ 
    $(this).siblings("div").text("ALWAYS OPEN"); }

Full working demo of the app: http://jsfiddle.net/DxaV7/ I have a ton of comments because I am pretty new to js and I need to walk myself though what I am doing (newb)

Thanks for any help you can provide!

glasses
  • 743
  • 2
  • 8
  • 24
  • you could also just check if(thisTimeSet.indexOf('Open 24 hours') > 0) but I think your selector within is wrong. I don't have the time to drill it down for you, but this can help get you pointed in the right area – Kai Qing May 21 '13 at 01:04

2 Answers2

3

Try this:-

Problem here is you have many spans with the same text so your === doesn't match. I am just using indexOf to find the instance of atlease one which would mean that it is "Always Open"

if (thisTimeSet.indexOf('Open 24 hours') > -1) {
        $(this).find('.openOrNot').text("ALWAYS OPEN");
}

Another thing to add is you are not looking at siblings of .module instead its child .openOrNot. So you need to use find to descend down instead of looking at the peers using siblings.

Demo

Edit:- As per your comment you can select spans that are only visible

var thisTimeSet = $(this).children("span:visible").text();

Demo

Community
  • 1
  • 1
PSL
  • 123,204
  • 21
  • 253
  • 243
  • Hey, great I think this is really close! but because in my demo locations, QDoba has some days(fri + sat) with "Open 24 Hours" it is throwing the "ALWAYS OPEN" flag even today, when they are not open 24 hours, do you have any ideas to fix this? There are 6 invisible spans with values in each box, and one visible one I want the statement that checks if the text is equal to "Open 24 hours" to only test the visible span for each .module if that makes sense – glasses May 21 '13 at 01:22
  • Updated the answer see if that s what you were looking for. – PSL May 21 '13 at 01:34
  • 1
    Awesome, this is perfect! Thank you so much! – glasses May 21 '13 at 01:35
0
if (thisTimeSet === 'Open 24 hours'){ 
    $(this).siblings("div:contains('ALWAYS OPEN')"); }
Manish Jangir
  • 505
  • 3
  • 9