0

I have a FlatIcon icon and i modified it via css like this:

[class^="flaticon-"]:before, [class*=" flaticon-"]:before,
[class^="flaticon-"]:after, [class*=" flaticon-"]:after {

    font-size: 55px;
    color: red;

}

The problem is that i have to modify the color via jquery as well.

I tried several ways, like this:

$('.flaticon-car:before').css('color',"#4286f4");
$('.flaticon-car:after').css('color',"#4286f4");
$('.flaticon-car').css('color',"#4286f4");
$('.flaticon-car:before').css({"color":"#4286f4"});
$('.flaticon-car:after').css({"color":"#4286f4"});
$('.flaticon-car').css({"color":"#4286f4"});

After that, i tried this:

$('.flaticon-car').click(function () {
    $(this).css('color','#4286f4');
});

Nothing worked for me.Do you have any ideea how can i do this?

Ioan Andrei
  • 93
  • 1
  • 16

1 Answers1

1

You can not style :after/before from Jquery

The trick is to toggle class

See example:

$('.className').click(function () {
   $( this ).toggleClass("newClassName");
});
.className:after,.newClassName:after
{
    position: absolute;
    content: '';
    font-size: 55px;
    background: red;
    width: 15px;
    height: 15px;
    left: 120px;
}

.newClassName:after
{
    background: #4286f4;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="className"> hello className</div>
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47