Character counter breaks after adding EmojiOne Area

I have a character counter for my textarea that was working great until I added EmojiOne Area. The emoji picker now works great, but my character counter stopped working. For some reason the keyup is no longer working off of the ID.

HTML

<textarea id="message" class="form-control" placeholder="Enter text here..."></textarea> 
<label><span id="chars" class="lead">140</span></label> characters left

Open in new window


JavaScript

/*emojioneArea */
$(document).ready(function() {
  $("#message").emojioneArea({
    pickerPosition: "bottom",
    tonesStyle: "bullet"
  });
});

/*Character Counter */
function countChar(val) {
  var len = val.value.length;

  if (len >= 140) {
    val.value = val.value.substring(0, 140);
    $('#stat span').text(0);
  } else {
    $('#stat span').text(140 - len);
  }
}
countChar($('#message').get(0));
$('#message').keyup(function() {
  countChar(this);
});

Open in new window


JSFiddle.
Jordan BenettAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Banshi lal dangiFull Stack DeveloperCommented:
As I can see there are few problems with you code. So I corrected the same and following is the updated working code with emojionearea and character count.
FYI - I came to got that, the same problem was also asked over the Stackoverflow and the below solution worked fine there as well. And Hope it will work for you as well.

/*emojioneArea */
   $(document).ready(function() {
         $("#message").emojioneArea({
                       pickerPosition: "bottom",
                       tonesStyle: "bullet",
                       events: {
                         keyup: function (editor, event) {
                           console.log('event:keyup');
                           countChar(this);
                        }
                      }
               });
    }); 

   /*Character Counter */
        function countChar(val) {
            var len = val.getText().length;
            if (len >= 140) {
                  val.value = val.content.substring(0, 140);
                  $('#chars').text(0);
            } else {
                 $('#chars').text(140 - len);
            }
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jordan BenettAuthor Commented:
Banshi, thank you for the solution, can you please share the Fiddle link, as I am not able to run it.
0
Banshi lal dangiFull Stack DeveloperCommented:
Sure Jordan, please find the fiddle link - Fiddle
0
Jordan BenettAuthor Commented:
Thanks a lot Banshi, That worked great!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.