Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  11] [ 5]  / answers: 1 / hits: 101659  / 15 Years ago, mon, july 27, 2009, 12:00:00

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



HTML :



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


jQuery :



$(#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 clicks on the button.

I know that filtering the elements in jQuery is using :button



This is what I have tried :



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


and



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


It didn't work



Anyone know how to do this?


More From » jquery

 Answers
36
$(#wrapper input[type=button]).click(function() {
alert(hi there);
});

[#99047] Wednesday, July 22, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazmyne

Total Points: 503
Total Questions: 102
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
jazmyne questions
;