开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜