jQuery On clear Button remove html Tag
Hi have a jQuery Validation on the form,
When user hits submit it generates an label tag as
<label for="LastName" generated="true" class="error">This field is required.</label>
<label for="FirstName" generated="true" class="error">This field is required.</label>
<label for="Email" generated="true" class="error">This field is required.</label>
<label for="DOB" generated="true" class="error">This field is required.</label>
I have a clear Button on the from when clicked it does the below stuff
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected')
$("#DOB").removeAttr('value');
But i also want to remove the labe开发者_开发技巧ls generated with the validation. I tried something like this
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected')
$("#DOB").removeAttr('value')
$( "label[for='LastName']" ).remove()
$( "label[for='FirstName']" ).remove()
$( "label[for='Email']" ).remove();
But it didn't work.
any help please?
Get them all in one go. All you need is:
$('.error').remove()
Your code but with semicolon at the end :). End it works.
$('#remove').click(function() {
$("label[for='DOB']" ).remove();
$("label[for='LastName']" ).remove();
$("label[for='FirstName']" ).remove();
$("label[for='Email']" ).remove();
});
Code: http://jsfiddle.net/LS2bE/1/
精彩评论