how to call a javascript function on all buttons with a class

Asked

Viewed 27 times

0

would like to call this function that is called all imput by id="inviardesb" and exchange them for all input you have <div class="classchama">

as I call by div this function

<div class="buttons">
<div class="classchama">
    <input type="submit" class="button" value="Cadastrar produto" id="inviardesb">
</div>
</div>  

Live.disableDataSubmit = function() {
    $("#inviardesb").on('click', function (event) {  
    $(this).attr('disabled', true);
    $(this).parents('form').submit();
    });
}
  • Could be more specific?

  • I think Voce wants all the buttons of a certain class by clicking on any of them to call a function, and this?

2 answers

0

If I understand correctly, just change the #inviardesb to . inviardesb:

Live.disableDataSubmit = function() {
$(".inviardesb input").on('click', function (event) {  
    $(this).attr('disabled', true);
    $(this).parents('form').submit();
});

0


In this case just change the dial, follows below:

<div class="buttons">
    <div class="classchama">
        <input type="submit" class="button" value="Cadastrar produto" id="inviardesb">
    </div>
</div>  

Live.disableDataSubmit = function() {
    $("div.classchama input").on('click', function (event) {  
        $(this).attr('disabled', true);
        $(this).parents('form').submit();
    });
}

The new selector is div.classchama input how detailed:

Selects all the tags div which contains the class classchama and then search for descendants that are a tag input

Browser other questions tagged

You are not signed in. Login or sign up in order to post.