Calendar Color Sharepoint "Javascript" "Jquery"

0

I have this code below for a calendar in sharepoint 2013 That when user choose car silver in the calendar field stay in silver color and when black stay in black color.

It works only in IE browser, in FireFox and Chrome does not work, does anyone have any idea what it might be?

    <script src="/sites/SiteAssets/jquery-2.1.4.min.js"></script> 
<style>

.black{
    background-color: #383838;
}

.silver{
    background-color: #C8C8C8;
}
</style><script type="text/javascript">

    $(function(){
        $('.ms-acal-item').each(function(){
            $(':contains("Preto")',this).addClass('black');
            $(':contains("Prata")',this).addClass('silver');
        });
    });
</script>
    
asked by anonymous 09.03.2017 / 22:14

1 answer

0

James, it's very simple what you want to do, so I understand just to switch between correct CSS classes? Here is a code that does exactly the same thing and I think it will not cause compatibility problems, you just refer to the "cars" click as it is referenced by the Toggle button ID.

$("#alternar").click(function() {
  if ($(".ms-acal-item").hasClass('black')) {
    $(".ms-acal-item").removeClass('black');
    $(".ms-acal-item").addClass('silver');
  } else {
    $(".ms-acal-item").removeClass('silver');
    $(".ms-acal-item").addClass('black');
  }
});
.black {
  background-color: #383838;
}

.silver {
  background-color: #C8C8C8;
}

.ms-acal-item {
  width: 100px;
  height: 50px;
  margin-bottom: 10px;
  border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='ms-acal-item'>
</div>

<button id='alternar'>
  Alternar Classe
</button>
    
09.03.2017 / 22:36