I've created a HTML/CSS/JavaScript snippet that does the following things:
- Includes a 'tick' on each button; and
- Once a button is clicked, it fades out
You can see a working example on JSFiddle.
Your question is a tad confusing, as the question title and body say different things:
Display Tick on button and reduce opacity when its clicked
Versus:
I would like for a tick to be shown on a button once it is clicked.
The CSS for this snippet can be easily modified to achieve either result.
Working Snippet
$( '.btnTicketType' ).click(function() {
$(this).addClass('clicked-button');
});
.btnTicketType {
margin-bottom: 2%;
margin-top: 10%;
width: 95%;
height: 15em;
font-size: 1.5em;
transition: all 1s;
}
.seatnumber{
display: block;
text-align: center;
font-size: 1em;
}
#rectangle{
overflow: auto;
outline-color: black;
outline-style: solid;
}
.clicked-button {
opacity: .1;
}
<link href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="rectangle">
<div class="col-md-3">
<button class="btnTicketType btn btn-default" value="">
<i class="fa fa-check" aria-hidden="true"></i>
Button 1
</button>
<small class="seatnumber">Text 1</small>
</div>
<div class="col-md-3">
<button class="btnTicketType btn btn-default" value="">
<i class="fa fa-check" aria-hidden="true"></i>
Button 2
</button>
<small class="seatnumber">Text 2</small>
</div>
<div class="col-md-3">
<button class="btnTicketType btn btn-default" value="">
<i class="fa fa-check" aria-hidden="true"></i>
Button 3
</button>
<small class="seatnumber">Text 3</small>
</div>
</div>
Additional Notes
A <button>
element is semantically valid:
The HTML <button>
element represents a clickable button.
A <button>
element can contain other HTML elements if required:
<button>
elements are much easier to style than <input>
elements. You can add inner HTML content (think <em>
, <strong>
or even <img>
), and make use of :after
and :before
pseudo-element to achieve complex rendering while <input>
only accepts a text value attribute.
Based on the above definitions, I've used Font Awesome to add the check icon to your buttons.
Your HTML incorrectly reused ID attributes. An id="btnTicketType"
attribute must be unique, and cannot be reused in valid HTML. If you need to style multiple elements, it's better to use a class="btnTicketType"
instead. I replaced the repeated ID attributes with classes instead for the HTML in my snippet.
If you're using the <button>
element in a <form>
, the value=""
attribute will be submitted with the form. From the MDN documentation:
value
The initial value of the button. It defines the value associated with the button which is submitted with the form data. This value is passed to the server in params when the form is submitted.