1

hi i have this html code

<div class='moves'>
    <div class='element'><input type='text' value='55' /></div>
    <input class='top' type='text' />
    <input class='Bottom' type='text' />
    <input class='left' type='text' />
    <input class='right' type='text' />
</div>
<div class='moves'>
    <div class='element'><input type='text' value='55' /></div>
    <input class='top' type='text' />
    <input class='Bottom' type='text' />
    <input class='left' type='text' />
    <input class='right' type='text' />
</div>
<div class='moves'>
    <div class='element'><input type='text' value='55' /></div>
    <input class='top' type='text' />
    <input class='Bottom' type='text' />
    <input class='left' type='text' />
    <input class='right' type='text' />
</div>

now what i want is when someone keyup inside top or bottom or left or right classes change the div at same parent position to the values or top left buttom right ect so i tried this

$(".top").keyup(function(){
    var element = $(this).parent().closest('.element');
    console.log(element);
})

i gat this message

w.fn.init [prevObject: w.fn.init(1)]

but what i want is to change position to the input with value 55 thanks a lot

1
  • 1
    var element = $(this).siblings('.element'); or var element = $(this).parent().find('.element'); or var element = $(this).prevAll('.element'); Commented Mar 31, 2019 at 15:30

1 Answer 1

1

closest() moves up (parent, parent of parent, ...), to find the element in children you should use find:

var element = $(this).parent().find('.element');

you also can use:

var element = $(this).siblings('.element');
Sign up to request clarification or add additional context in comments.

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.