Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:48:56+00:00 2026-05-26T22:48:56+00:00

I have this jQuery code: var char = 60; $(#counter).append(You have <strong> + char

  • 0

I have this jQuery code:

var char = 60;
    $("#counter").append("You have <strong>" + char + "</strong> char.");
    $("#StatusEntry").keyup(function () {
        if ($(this).val().length > char) {
            $(this).val($(this).val().substr(0, char));
        }
        var rest = char - $(this).val().length;
        $("#counter").html("You have <strong>" + rest + "</strong> char.");
        if (rest <= 10) {
            $("#counter").css("color", "#ff7777");
        }
        else {
            $("#counter").css("color", "#111111");
        }
    });

It works fine!
But if instead a val() I have text() it doesn’t work.

The problem is that at the end of available char it start to replace the text from the beginning…… using val is perfect.

Why I need it on text?
Because I’m using a wysiwyg plugin and it convert my textarea to div.

I’m trying with .stopPropagation but it doesn’t work.. trying with return false and nothing…

Hope in your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:48:56+00:00Added an answer on May 26, 2026 at 10:48 pm

    If you need to use the NicEdit then you can limit the keystrokes by binding the keyup / keydown event to the newly created div (it doesnt replace your textarea – its adds a div and hides your textarea) :

    $("#StatusEntry").prev().keydown(function () {
    

    This works because the newly create div is always preceding the textarea – so this will work for multiple editors.

    However as you seem to have indicated in your comments a contentEditable div may be sufficient – if it is use the following method :

        var char = 60;
        $("#counter").append("You have <strong>" + char + "</strong> char.");
        $("#StatusEntry").keyup(function () {
            if ($(this).text().length > char) {
                $(this).text($(this).text().substr(1));
            }
            var rest = char - $(this).text().length;
            $("#counter").html("You have <strong>" + rest + "</strong> char.");
            if (rest <= 10) {
                $("#counter").css("color", "#ff7777");
            }
            else {
                $("#counter").css("color", "#111111");
            }
        });
    

    Demo : http://jsfiddle.net/RjNuX/3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in jquery : $(#order_btn).click(function(){ var totalprice = $(.price_amount).text(); $(#totalprice).val(totalprice); });
I have this code in jQuery.. $(document).ready(function(){ var fieldCounter = 0; ... I have
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have this jQuery code: $(.right_box_holder).sortable({ update : function () { var order =
I have this jquery code : $(document).ready(function() { $('div.badge_button > .more').click(function() { var id
I have this jQuery code: var help; $('.helpPin').click(function(){ if(help == true){ var cssObj =
i have this code // jquery $(document).ready(function() { $('#update_point').live(change, function() { var point_val =
I have this jquery code: $(document).ready(function() { function slideSwitch() { var $active = $('#slideShow
I have this JQuery code: $(div.notification).live(click, function(){ window.location=$(this).find(a).attr(href); var myId = $(this).attr(id); $.post(/videos/selected_notification.js, myId);
I have this jQuery code: <script type=text/javascript > $(function() { $('#add_comment').bind('submit',function() //$(input[type=submit]).click(function() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.