Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery clear values of all input fields except one

Tags:

jquery

loops

I am trying to write a script which clears the value of all input fields except for one. This script is still clearing the DESCRIPTION input field.

jQuery('.campaign-column').not('active').each(function(index){
    if(jQuery('.campaign-column input[name!="DESCRIPTION"]')){
        jQuery(this+':input').val('');
        }
    });
like image 427
user1413248 Avatar asked Dec 20 '22 16:12

user1413248


1 Answers

Simplify:

$('.campaign-column:not(.active) input:not([name="DESCRIPTION"])').val('')

I assume you meant .not('.active') and not .not('active'), since there is no <active> element in HTML. Note, the loop (.each()) in your original code is pointless, since every iteration selects, over and over, the same elements.

like image 72
Matt Ball Avatar answered Jan 09 '23 15:01

Matt Ball