views:

170

answers:

2
 if (tag == 'td' && $(this).hasClass('status')) {
        // I am clearing everything inside the td with class status
        $(this).html('')
    }

But it doesn't seem to clear... Any suggestion...

I am customizing a form plugin,

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea' )
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
        else if (tag == 'td' && $(this).hasClass('status')) {
            // if you want to remove everything, use this
            $(this).html('');
        }
    });
};
+2  A: 

Why not just do:

$('td.status').empty();
Neil T.
@Neil look at my edit...
Pandiya Chendur
+1  A: 

Looking at the code (in your edit), and assuming you call the function by doing something like $('#myForm').clearForm() (where myForm is a form element), then its never going to process td elements. The code takes a form & then recurses onto that form's :input elements to clear them. Given that td is not an input, they won't be included in the clearing.

If that is how you're using it, you could customise it as follows to get it to clear your tds (within the form) as well:

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form') {
            $('td.status', this).empty();
            return $(':input', this).clearForm();
        }
        if (type == 'text' || type == 'password' || tag == 'textarea' )
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};
Alconja
@Alconja any other possibility...
Pandiya Chendur
@Pandiya: how are you calling the plugin?
Alconja
@alconja `$("#addform").clearForm();`
Pandiya Chendur
@alconja `$('td.status', this).empty();` this doesn't seem to work...
Pandiya Chendur
@pandiya - Oops, I obviously didn't read what I posted. That line was after a return statement. :) Fixed now.
Alconja
@Alconja ya i too didnt seem that
Pandiya Chendur