Clear all textboxes except few

http://jquerytipsntricks.wordpress.com

by Akram kamal

HTML

<!-- http://jquerytipsntricks.wordpress.com -->
<h2>Clear all textboxes except few</h2>
<br/>
<h3>Demo #2</h3>
<span>Please click on the Clear button to clear all textboxes except 2<sup>nd</sup> &amp; 3<sup>rd</sup></span><br/><br/>
<div id="parent"> 
    <input type="text" id="one" value="one" /><br/>
    <input type="text" id="two" value="two" class="ignore" /><br/>
    <input type="text" id="three" value="three" class="ignore" /><br/>
    <input type="text" id="four" value="four" /><br/><br/>
    <button id="clear">Clear</button>
</div>
<footer>
    <p><a href="http://jquerytipsntricks.wordpress.com/" target="_blank">jQuery Tips n Tricks</a> 2014</p>
</footer>
<!-- http://jquerytipsntricks.wordpress.com/ -->

CSS

/* http://jquerytipsntricks.wordpress.com */
body {
    font: 11px/18px 'lucida grande',tahoma,verdana,arial,sans-serif;
    color: #666;
}
h2 {
    font-size: 18px;
    line-height: 24px;
    margin-bottom: 0;
    color: #333;
    border-bottom: 1px solid #e1e1e1;
    padding-bottom: 15px;
}
footer {
    position:fixed;
    left:0px;
    bottom:0;
    width:100%;
    border-top: 1px solid #e1e1e1;
    padding-left:10px;
}
/* http://jquerytipsntricks.wordpress.com */

JavaScript

// Bind an event handler to the "click" JavaScript event
$('#clear').click(function(){
    
    // Selects all elements of type text and clear all
    $('#parent > input:text:not(".ignore")').val('');            
});