Rose Perrone
Rose Perrone

Reputation: 63556

Adding onClick action

When I click button A, I want it to modify the onClick action of a Done button.

Here's the done button:

<a href="#" class="btn" data-dismiss="modal" class="done-btn">Done</a>

After I click button A, this code is executed (the alert "A" pops up):

            <script type="text/javascript">
                $(document).ready(function() {
                    // make the items table reload when the dismiss button is clicked
                    alert("A");

                    $(".done-btn").on(function() {
                        alert("Done button clicked.")   
                    });
                }); 
            </script>;

I have also tried click(), onclick =, and removing the $(document).ready wrapper.

Upvotes: 1

Views: 544

Answers (3)

w00
w00

Reputation: 26772

You forgot to specify on what the action should perform. Add 'click' to the on function.

Try this:

        <script type="text/javascript"> 
            $(document).ready(function() { 

                $(".done-btn").on('click', function() { 
                    alert("Done button clicked.")    
                }); 
            });  
            </script>; 

Upvotes: 2

Jeff Gortmaker
Jeff Gortmaker

Reputation: 4737

You have two class= in your html. Simplify it to:

<a href="#" class="btn done-btn" data-dismiss="modal">Done</a>

Change your javascipt to:

$(document).ready(function() { 
    $(".done-btn").click(function() { 
        alert("Done button clicked.")    
    }); 
});

Upvotes: 1

Martin Majer
Martin Majer

Reputation: 3352

Try this:

$(".done-btn").click(function() {
    alert("Done button clicked.")   
});

And change the HTML to this:

<a href="#" data-dismiss="modal" class="btn done-btn">Done</a>

Upvotes: 0

Related Questions