Show div on onclick independent of clicked button

Asked

Viewed 187 times

1

I know little of javascript and on my page I have a button that, when clicked, calls a div. So far so good, but the function takes the id button, ie if I put more than one button on the page and need to call the div will not work. I need to change the function to grab the button by parameter in the onclick and not fixed by id.

How are you:

<button type="submit" id="submitbtn">//Gostaria de chamar a função no onclick passando qualquer botão como parametro

Function:

    $(function () {
    $("#submitbtn").click(function () {//Aqui seria a passagem do parâmetro
        $("#loading").fadeIn();
        var opts = {
            lines: 12, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            color: '#000', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false // Whether to use hardware acceleration
        };
        var target = document.getElementById('loading');
        var spinner = new Spinner(opts).spin(target);
    });
});

1 answer

2


Add a class to the buttons and use this class in javascript, for example:

<button type="submit" id="submitbtn" class="botaoMostraDiv">

and then change your javascript from ("#submitbtn").click(function () { ...

for $(".botaoMostraDiv").click(function () {...

Browser other questions tagged

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