Reputation: 33
I want to set a textbox inside a button. I'm having trouble with the click event of the text box - whenever I click the textbox, it clicks the button as well and fires the button's event. I want to separate those two events - so when I'll click the textbox in order to type, it won't fire the event that's connected to the button click. How can I accomplish that?
Edit: I've tried using stopPropagation and preventDeafult but the event of the button fires before it reaches my event.
Upvotes: 0
Views: 106
Reputation: 870
Maybe there's something wrong with the HTML layout, Here's something that works just fine, by giving a z-index to each element:
HTML:
<div style="z-index: 2; position:absolute; top:0">
<input id="text" type="text"/>
</div>
<div style="z-index: 1; position:absolute; top:0 ">
<input id="button" style="width:200px; height:40px; text-align:right" type="Button" value="button"/>
</div>
JS:
$("#text").click(function(){
alert("text clicked");
});
$("#button").click(function(){
alert("button clicked");
});
Here's a live demonstration
Upvotes: 0