Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $(this).children not working?

Tags:

jquery

I'm sure jQuery works fine, but for some reason it isn't for me. I can't even put it into a jsFiddle because it doesn't like Ajax, but my statements involving $(this).children are not working at all. I'm not getting any errors... what am I doing wrong?

JS

$('.submitNewOrder').submit( function() {
    $(this).children('input[type=\"submit\"]').prop('disabled',true); // Doesn't work
    $(this).children('.saving').fadeIn('fast');  // Doesn't work
    $.ajax({
        url: 'scripts/submitNewOrder.php?catID=1',
        data: newOrder,
        type: 'POST',
        mode: 'abort',
        success: function(){
            $(this).children('.saving').fadeOut('fast', function() { // Doesn't work
                $(this).children('.success').fadeIn('fast'); // Doesn't work
            });
        },
        error: function(){
            $(this).children('.error').fadeIn('fast'); // Doesn't work
        }
    });
    return false;
});

HTML

<form class="submitNewOrder">
    <p>
    <input type="submit" value="Save order" />
        <span class="saving" style="display:none">Saving changes...</span>
        <span class="success" style="display:none">Saved!</span>
        <span class="error" style="display:none">There was a problem saving :(</span>
    </p>
</form> 
like image 528
Chuck Le Butt Avatar asked Feb 05 '26 02:02

Chuck Le Butt


1 Answers

Try replacing the children with find like:

$('.submitNewOrder').submit(function () {
    var $this = $(this);
    $this.find('input[type=\"submit\"]').prop('disabled', true); 
    $this.find('.saving').fadeIn('fast'); 
    $.ajax({
        url: 'scripts/submitNewOrder.php?catID=1',
        data: newOrder,
        type: 'POST',
        mode: 'abort',
        success: function () {
            $this.find('.saving').fadeOut('fast', function () { 
                $this.find('.success').fadeIn('fast'); 
            });
        },
        error: function () {
            $this.find('.error').fadeIn('fast'); 
        }
    });
    return false;
});
like image 81
palaѕн Avatar answered Feb 08 '26 12:02

palaѕн



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!