RGriffiths
RGriffiths

Reputation: 5970

How to stop one Submit button from running the Submit Click function

I have page where there are number of Submit buttons and a loading gif is displayed when any of the buttons are pressed:

<script>
$(document).ready(function(){
    $(".loader").hide();
    $(".overlay").fadeOut(1000);

    $("[type='submit']").click (function(){
        $(".loader").fadeIn("fast");
        $(".overlay").fadeIn(1000);
    });
}); 
</script>

This works well but there is one button that where I do not want the loading gif to be displayed. I have set the Submit to have an ID:

<form action ="https://.../csvdownload.php">
    <input type = "submit" value="CSV download" id="noloader">
</form>

The php runs in the background and the current page is not actually left from view.

How do get the loader to not be displayed for this Submit?

Upvotes: 1

Views: 34

Answers (1)

metarmask
metarmask

Reputation: 1857

Use the $(...).is() function to check if the clicked element has the noloader id.

$("[type='submit']").click (function(){
    // If the clicked element isn't the noloader element
    if(!$(this).is("#noloader")){
        // Display the loader
        $(".loader").fadeIn("fast");
        $(".overlay").fadeIn(1000);
    }
});

Upvotes: 3

Related Questions