1

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");
}

1 Answer 1

2

: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");
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

@NunoNogueira It works here jsfiddle.net/zs42v Is the script appearing after the element as you have shown in your example if not wrap it in $(function(){...});
that was exactly the problem, I guess... The script was being loaded before the element.. Thanks for your help!
I sure don't. There it is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.