walter
walter

Reputation: 11

Using find() excluding some elements?

I need to use find() to find all inputs in a form and change its value to ''. But I also need to exclude 2 inputs, the name of these inputs are: 'data', and 'date'

I tried this (with no success)

$('#contactForm').find("input[ @name != 'data' ][ @name != 'date' ]").val('');

Upvotes: 1

Views: 97

Answers (2)

Jacob Relkin
Jacob Relkin

Reputation: 163288

Use jQuery's not method:

$('#contactForm').find('input').not("[name='data'],[name='date']").val('');

Here's a jsFiddle example.

Upvotes: 2

Ali Tarhini
Ali Tarhini

Reputation: 5358

$('input').each(function(){
 if ( this.name != 'data' && this.name != 'date')
     this.value = '';
});

Upvotes: 0

Related Questions