I have an "clear"-icon dynamically showing up in my input-field when I write something. Keypress and focus events handle that well, the only thing is that I want the icon to be removed when the input field is not in focus mode. The problem is that I have a click event on the icon, so if I click the icon, the focusout-event fires. I can't figure it out.
$(".searchInput").focusout(function(e) {
console.log(e);
if(e.currentTarget != this) {
if ($(".keypress").length > 0) {
$(".keypress").remove();
}
}
})
I've put together a little fiddle: http://jsfiddle.net/w9RbW/.
As you can see, if the input value isn't empty, the icon is still there, I don't know how to check if it's being clicked, or something like that...