0

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

        });
7
  • api.jquery.com/find Commented Mar 25, 2015 at 18:42
  • 1
    your input has class of OnHandEditClass, not OnHandClass. Commented Mar 25, 2015 at 18:45
  • 1
    @PlantTheIdea - OP said the "cell" has the class OnHandClass. Presumably the input is in a table cell however the OP failed to include that code if it is. Commented Mar 25, 2015 at 18:47
  • @j08691 - ah, so they just provided an incomplete codebase for the question. my bad. Commented Mar 25, 2015 at 18:48
  • Either that or a bad description. Commented Mar 25, 2015 at 18:48

3 Answers 3

2

Using .find() (or .children()) should do it:

$('.OnHandClass').dblclick(function (evt) {
    $(this).find(":text").show();
});

jsFiddle example

.next() searches the immediate sibling and .closest() looks up the DOM, so neither of those should have worked for you.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Mike. Please see my edit above. My OnHandClass is on a table cell.
0

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.