2

i am trying to highlighted selected radio button using Attribute Binding but i am not getting result can some one help me please

css

input:default {
  box-shadow: 0 0 1px 1px red;
}

html

<input type="radio" name="gender" value="male" [attr.default]="value=='male'" (click)="value='male'"> Male<br>
<input type="radio" name="gender" value="female" [attr.default]="value=='female'" (click)="value='female'"> Female<br>
<input type="radio" name="gender" value="other" [attr.default]="value=='others'" (click)="value='other'"> Other

Below my stackblitz link

https://stackblitz.com/edit/angular-648y1w?file=src/app/app.component.html

4
  • Your selector is wrong Commented Jan 16, 2019 at 8:51
  • stackblitz.com/edit/angular-ehh4tr Commented Jan 16, 2019 at 8:52
  • but i am not getting result - So what is the problem? you do get 3 radio buttons, which is selectable. Commented Jan 16, 2019 at 8:52
  • Krish, I think that default it's only for buttons (I'am not 100% sure). In your stackblitz you has input[type=checkbox], must be input[type="radio"] -see that type goes between quotes. You can use simply "checked" in your .css and no code input[type="radio"]:checked Commented Jan 16, 2019 at 8:58

1 Answer 1

1

Your css selector is wrong

it should be like this

input[type="radio"][default="true"] {
  box-shadow: 0 0 1px 1px red;
}

demo

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

4 Comments

demo links to this SO question
i have small doubt your saying my css is wrong but i followed this official link its working fine w3schools.com/cssref/sel_default.asp
can you please explain me ?
@Krish The :default selector selects the default form element in a group of related elements. means when it renders and finds the radio checked on that element css will be applied, your case is of attribute not default selected.

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.