Can't get a conditional statement to work...help please!
I'd like to inject the class name "in" into a div if the div contains the text "In" or "Remote", and for everything else have the class name "out" get injected instead. The first part of the
if statement seems to be working but the second part, the
else part, doesn't seem to work. Here is my code:
- (function ($){
- Drupal.behaviors.at_topnav = {
- attach: function(context, settings) {
-
- var i = $('div.user_status:contains("In", "Remote")');
- if ( i ) {
- $('div.user_status').addClass('in')
- }
- else {
- $('div.user_status').addClass('out')
- };
- }
- };
- })(jQuery);
HTML:
- <div class="wbuser">
- <div class="user_status">In</div>
- </div>
- <div class="wbuser">
- <div class="user_status">Out</div>
- </div>
- <div class="wbuser">
- <div class="user_status">Remote</div>
- </div>
- <div class="wbuser">
- <div class="user_status">OOB</div>
- </div>
CSS:
- .wbuser .user_status {
color: #666666;
float: left;
position: relative;
right: 83px;
text-indent: 25px;
word-wrap: normal !important;
}
.wbuser .in {
background: #7EA43F;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
height: 15px;
width: 15px;
}
.wbuser .out {
background: #CC6616;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
height: 15px;
width: 15px;
}