Reputation: 3156
I have a cell with a class called OnHandClass. I have an input field inside the cell and I have added a double click event to the cell and have tried many ways to change the visibility of the closest input element. Three are listed below. What am I missing ?
<input type="text" class="OnHandEditClass" value="1" style="display: none;">
<td class="OnHandClass">
1
<input type="text" class="OnHandEditClass" value='1'>
</td>
$('.OnHandClass').dblclick(function (evt) {
$(this).next(":text").css("display", "inline");
$(this).next("input[type='text']").show();
$(this).closest('input').css("display", "inline");
});
Upvotes: 0
Views: 71
Reputation: 617
If your input is inside your td as you said, use .children:
$('.OnHandClass').dblclick(function() {
$(this).children('input').css("display", "inline");
});
.children should be the fasted way in your case.
Upvotes: 0
Reputation: 207891
Using .find()
(or .children()
) should do it:
$('.OnHandClass').dblclick(function (evt) {
$(this).find(":text").show();
});
.next()
searches the immediate sibling and .closest()
looks up the DOM, so neither of those should have worked for you.
Upvotes: 2
Reputation: 691
<input type="text" class="OnHandClass"/>
<input type="text" class="OnHandEditClass" value="1" style="display: none;">
$('.OnHandClass').dblclick(function(evt) {
$(this).closest('input').next().css("display", "inline");
});
Upvotes: 0