1

I want to achieve the below:

  1. when the checkbox is checked: change the value to green
  2. When the checkbox is unchecked: change the value to black

CSS:

`<style>
  input[type="checkbox"]:checked + value:before{
  color: green;
}
</style>`

HTML

              <tr class="bg-primary text-white">                  
                <th scope="col" class="text-left">Email 1</th>                          
              </tr>


<ng-container *cdkVirtualFor="let contact of myContact">
              <tbody >
              <tr style="width:100%; min-height: 30px;">                   
                <td class="text-left " [title]="contact.mail1">
                   <input type = "checkbox"   value="{{contact.emails}}" id="checkboxEmail1"
                          [checked]="contact.emails === 1 || contact.emails === 3"
                          (change)="editContactEmail1(contact.id, $event)"
                          [disabled]="contact.sajpContact != 1" />
                  {{(contact.mail1.length>25) ? (contact.mail1 | slice:0:25) + '...' : (contact.mail1)}}
                </td></tr></tbody></ngcontainer>
1
  • Just change input itself: input[type="checkbox"]:checked {} Commented Jan 31, 2020 at 12:50

2 Answers 2

2

You should add the following jQuery code:

$('input[type="checkbox"]').click(function() {
    if ($(this).is(":checked")) {
        setTimeout(() => { $(this).css({'outline': '2px solid green', 'outline-offset': '-2px'}); }, 1000);
    } else {
        setTimeout(() => { $(this).css({'outline': '2px solid black', 'outline-offset': '-2px'}); }, 1000);
    }
});
Sign up to request clarification or add additional context in comments.

4 Comments

I bind the checkbox value. I would want to set a timeout for the checkbox value to change color when checked and back to default color.
So you suggest using jQuery?
Answer updated. (as it turns out to be impossible to change the checkbox color without creating a custom one, I add an outline to the checkbox)
Thank you Bonfire.
0

And don’t put the `

<style> ...

Quotes!

Is it normal ? Is it server-side format ?

Comments

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.