10

I've got a form that I clear on focus. I've selected the whole form and it works great except that the submit button goes blank when I click it.

how can I exclude my input of input#submit from the following code?

    $(".wpcf7-form input, .wpcf7-form textarea").focus(function() {
 if( this.value == this.defaultValue ) {
  this.value = "";
  $(this).addClass('filled');
 }
}).blur(function() {
 if( !this.value.length ) {
  this.value = this.defaultValue;
  $(this).removeClass('filled');
 }
});

5 Answers 5

12

Use the not selector to exclude what you want:

$(".wpcf7-form input:not('#submit_id'), .wpcf7-form textarea").focus(function() {
 // your code......
}

Or

$(".wpcf7-form input:not(input[type=submit]), .wpcf7-form textarea").focus(function() {
 // your code......
}
Sign up to request clarification or add additional context in comments.

Comments

7

Use .not() to exclude your input button (or buttons) from the set of inputs you already have.

$('input.are.blong.to.us') // give me a bunch of inputs
    .not('#submit')        // exclude input#submit
    .focus( ... )          
    .blur( ... );

Comments

2

You want the not-equal to selector:

.wpcf7-form input[id!=submit]

or

.wpcf7-form input[type!=submit]

Comments

1
$(".wpcf7-form input:not(#submit), .wpcf7-form textarea")

not

2 Comments

Even simpler: $(".wpcf7-form :input:not(#submit)") as :input includes textarea.
@Tatu Ulmanen: That's not the same though, does he want <select> as well?
1

You could use the css3-not selector.

A selector like that would be: input:not([type=submit]).

Example here: JsFiddle.

More info about the not-selector here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.