MasterJoe
MasterJoe

Reputation: 29

Change class name based on text of the next span tag

I have an html below:

<td class="status">
  <span class="fa fa-times-circle" aria-hidden="true"></span>
  1
</td>

I want to change the span class to "fa-sun-o" if the class "status" text is 0. The code that I have below doesn't work for some reasons. Can anyone help?

<script>
    if $(".status:contains('1')") {
        $('.status').nextAll('span:first').removeClass('fa-times-circle').addClass('fa-sun-o');
      }
</script>

Upvotes: 0

Views: 267

Answers (1)

Derek Story
Derek Story

Reputation: 9583

You don't need an if statement for this. You can just do:

$('.status:contains("1") span').removeClass('fa-times-circle').addClass('fa-sun-o');

Codepen

Upvotes: 1

Related Questions