2 Replies Latest reply on Nov 27, 2014 5:50 PM by Xoco

    Problem with jQuery html() Method

    Xoco Level 3

      I try to use jQuery html() Method for to show letter to letter a string.

       

      for( i = 0; i < conEmpresa.length; i++){

           text += conEmpresa.substring(i, i+1);

           sym.$("conEmpresa").html(text);

      }

       

      But always show all complete string. I try too:

       

      for( i = 0; i < conEmpresa.length; i++){

           text += conEmpresa.substring(i, i+1);

           setTimeout( function(){ sym.$("conEmpresa").html(text); }, 100);

      }

       

      But nothing, any ideas? Thanks.

        • 1. Re: Problem with jQuery html() Method
          joel_pau Level 5

          So,

           

          One solution:

          sym.$("Text").html("");

          var increment = 0;

          var str = "A typewriter effect. You can change this text.";

          var timer = setInterval(function() {

          sym.$("Text").html(str.substring(0, increment++));

          if (increment >= str.length) clearInterval(timer);

          }, 100);

           

          Another solution:

          sym.$("Text").html("");

          var text = "A typewriter effect. You can change this text.";

          $.each(text.split(""), function(index, item){

          setTimeout(function(){ sym.$("Text").html(sym.$("Text").html() + item) }, 100*index);

          });

           

           

          Findings: You've got 2 solutions: with or without jQuery file. It means also before and after Edge 5.0

          • 2. Re: Problem with jQuery html() Method
            Xoco Level 3

            Both solutions work fine, but only with first solution the HTML br tag are displayed correctly.

             

            Thanks for all.