0

Is it possible to change the button css based on values. I want to have different css for Save and different css for Cancel for type button.

Ex:

<input type="button" value="Save">
<input type="button" value="Cancel">

save { /* Some CSS */ }
cancel{ /* Some CSS */ }

NOTE : I cannot use class as all the input is having same class as there are plenty of buttons. Also I dont want to use Jquery.

3
  • in css use input[value=save]{.......} Commented Sep 29, 2016 at 9:35
  • @Tommy I have edited the question. If i target value directly it will effect the textbox with text save. I want to target type button with save value. Is that possible ? Commented Sep 29, 2016 at 10:31
  • input[value=save][type=button] Commented Sep 29, 2016 at 14:41

3 Answers 3

11

Yes, with an attribute selector.

input[value="Save"] {
  color: red;
}
input[value*="Cancel"] {
  color: blue;
}
<input type="submit" value="Save">
<input type="submit" value="Cancel">
<input type="text" value="Cancel-me-too">

To target specific button type you need more than one attribute selector

input[type="submit"][value="Save"] {
  color: red;
}
input[type="submit"][value*="Cancel"] {
  color: blue;
}
<input type="submit" value="Save">
<input type="submit" value="Cancel">
<input type="text" value="Save">

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

1 Comment

I have edited the question. If i target value directly it will effect the textbox with text save. I want to target type button with save value. Is that possible ?
1

Use CSS Attribute Selectors :

input[value="Save"] {background:green;}
input[value="Cancel"] {background:grey;}

1 Comment

I have edited the question. If i target value directly it will effect the textbox with text save. I want to target type button with save value. Is that possible ?
1

I think jquery seems to be no need.
Button is large, the class must be used.
Try this code.

<style type="text/css">
input[value="Save"] {
  color: green;
}
input[value*="Cancel"] {
  color: black;
}
</style>
<input type="submit" value="Save">
<input type="submit" value="Cancel">

1 Comment

I have edited the question. If i target value directly it will effect the textbox with text save. I want to target type button with save value. Is that possible ?

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.