squiroid
squiroid

Reputation: 14037

Textarea Auto scroll down

I know this can be done with the .change() event and put $('#console').scrollTop($('#console')[0].scrollHeight); in it.But problem is that textarea is readonly and I am using javascript to enter the text in textarea.

For ex:-

$('#console').text($('#console').text()+'\n>_ Optained Trigger');

In this case the textarea is not scrolltobottom because change event it not responding.

Any alternative for it or any other event that capture javascript text change in textarea?

Upvotes: 0

Views: 602

Answers (1)

fixmycode
fixmycode

Reputation: 8506

You can chain jQuery operations that affect your element without the need of events:

$('#console').text($('#console').text()+'\n>_ Optained Trigger').scrollTop($('#console')[0].scrollHeight);

edit: Ok, I read your comments, and to solve that you could trigger the change event manually

//first define the event behaviour
$('#console').on('change', function(e){
    var console = $(this);
    console.scrollTop($('#console')[0].scrollHeight);
}

//then every time you modify the text, trigger the event
$('#console').text($('#console').text()+'\n>_ Optained Trigger').trigger('change')

Upvotes: 1

Related Questions