Add remove class for input element
Description
The following code shows how to add remove class for input element.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type="text/javascript"
src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.js"></script>
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.css">
<style type='text/css'>
.tap-button {<!-- w ww.j a va2 s . c om-->
background: red;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$("#name").on('click', function (event) {
$(this).closest('div').addClass('tap-button');
$(this).on('keypress', function () {
$(this).closest('div').removeClass('tap-button');
});
});
});//]]>
</script>
</head>
<body>
<input type="text" id="name" placeholder="type">
</body>
</html>