views:

1983

answers:

1

Hi again all jQuery coder

I have a problem with selecting and filtering elements inside a div.

My html looks like this

<div id="wrapper">
    <input type="text" value="you can edit me">
    <input type="button" value="click me">
</div>

and my jQuery looks like this

$("#wrapper").children().click(function() {
    alert("hi there");
});

The problem is I get alerted every time I click anything inside the div But my requirement is to alert only when the user click on the button I know that filtering the elements in jQuery is using ":button"

I have tried

$("#wrapper").children(":button").click(function() {
    alert("hi there");
});

or

$("#wrapper").children().filter(":button").click(function() {
    alert("hi there");
});

It didn't work

Anyone know how to do this?

+5  A: 
$("#wrapper input[type=button]").click(function() {
    alert("hi there");
});
John Kugelman