I have an input with an X (clear) button to clear the value. I want that button to fadein if there is a value in the input.
Here is a fiddle of what I have: http://jsfiddle.net/3m25K/
<input class="inputfield">
$('input.inputfield').wrap('<span class="deleteicon" />').after($('<span/>').click(function() {
$('.inputfield').val('').focus();
}));
input{
font-size:22px;}
span.deleteicon {
position: relative;
}
span.deleteicon span {
position: absolute;
display: block;
top: -5px;
right: 7px;
width: 24px;
height: 24px;
background:black;
cursor: pointer;
}
You could just add a
keyuphandler and check the if the<input>‘s value has transitioned from none to some or some to none and then apply afadeInorfadeOutto the button. Something like this:Live version: http://jsfiddle.net/ambiguous/MDnac/3/