2

function mutevideo(evt) {
  if (evt.target.classList.contains('fa-video-camera')) {
    evt.target.classList.remove('fa-video-camera')
    evt.target.classList.add('fa-video-camera:after') // need here above fontawesom class with slash
  } else {
    evt.target.classList.remove('fa-video-camera:after') // need here above fontawesom class with slash
    evt.target.classList.add('fa-video-camera')
  }
}
.fa-video-camera:after {
  position: absolute;
  content: "/";
  color: white;
  font-weight: 900;
  font-size: 20px;
  left: 10px;
  top: 7px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

<p class="bg-white text-danger rounded-circle"><i onClick=mutevideo(evt) class="fa fa-video-camera p-2 fa-1x"></i></p>

Problem:-

In fontawesome 4.7 version it don't have slash video as it have in version of 5.x, so here i wrote my own css with :after to make this achieve, Now how where i will get video slash as soon as page loads, but my requirement is i need slash on icon after i click.

Note:-

here i'm using fontawesome version 4.7, any help or suggestion are heartily thank you

7
  • You can NOT access :after like this in JS as its not part of the DOM so it will not able accessible. Commented Jul 25, 2020 at 13:41
  • hi @AlwaysHelping, thank you for your suggestion, can you please show me how can i achieve this. Commented Jul 25, 2020 at 13:43
  • @unique What are trying to achieve? Commented Jul 25, 2020 at 13:44
  • :after (or ::after) in CSS refers to adding content after an element; it's not part of the class name, and has nothing to do with "after it's been clicked". Commented Jul 25, 2020 at 13:44
  • Also note that although you say "the above code works fine", clicking "Run Snippet" actually results in an error. Please edit to make sure you have a minimal reproducible example, along with a clear explanation of what you are trying to achieve. Commented Jul 25, 2020 at 13:47

1 Answer 1

3

You can simply use a custom class .stop to add a slash in your font-awesome icon on click. There is no need to add another icon to add a slash.

To show and hide on click we can simply use toggle() function instead of doing alot of if's and else or add or remove classes

Run snippet below.

function mutevideo(evt) {
  if (evt.classList.contains('fa-video-camera')) {
    evt.classList.toggle('stop')
  }
}
.stop:after {
  position: absolute;
  content: "/";
  color: white;
  font-weight: bold;
  font-size: 23px;
  left: 11px;
  top: 12px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<p class="bg-white rounded-circle"><i onClick=mutevideo(this) class="fa fa-video-camera p-2 fa-1x"></i></p>

Sign up to request clarification or add additional context in comments.

1 Comment

thank you @alwayshelping, this saved my day, i was trying this from past 5 hrs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.