Abdelhadi Tawil
Abdelhadi Tawil

Reputation: 33

Why scrolling position change after Focus the input?

I have a editable text when i click in the text the div change into input keeping the text my problem is when i click into the text the div change into input but scroll position change.

Jquery code:

$('.content-comment').click(function(){
    $('.content-comment').hide();
    $('.content-comment-input').show();
    $('.content-comment-input').val($(this).text());
    $('.content-comment-input').focus();
});

HTML code:

<div class="comment-c">
      <div class="user-pic-c ></div>
      <div class="elements-comment">
           <div class="content-comment clear"><?php echo $k['test']; ?></div>
           <input class="content-comment-input" type="text" value="" style="display:none;">
     </div>
</div>

Upvotes: 1

Views: 681

Answers (1)

Hadi Sharifi
Hadi Sharifi

Reputation: 1527

It's simple because you change input value, so the position on your input will be changed. if you comment below line I assume it's work fine.

$('.content-comment').click(function(){
    $('.content-comment').hide();
    $('.content-comment-input').show();
    //$('.content-comment-input').val($(this).text());
    $('.content-comment-input').focus();
});

Upvotes: 1

Related Questions