user882670
user882670

Reputation:

jQuery button selector with click event not working

Why is this not working?

<div id="download">
        <button>Download</button>
</div>

$("#download").find( ":button" ).click(function () {
    alert("io");
});

I tried adding a class and an Id to the button element. I also tried

<button>Download</button>

$(':button').click(function(){
    alert("io");
}

Upvotes: 1

Views: 1165

Answers (1)

PSL
PSL

Reputation: 123739

:button matches only <input type="button"...

so try:

$(function(){ //And i would wrap it in DOM ready wrapper if the script is loaded earlier than the element in DOM.
    $("#download").find("button").click(function () {
        alert("io");
    });
});

Upvotes: 2

Related Questions