0

Question :

I need to filter each letter in the paragraph tag using jquery each but it is not working .

HTML

  <p id="check">This is kamesh</p>

jQuery

var text = $(this).text(),
    jQuerytext = $(this) ,
    funtext ='' ,
    colorToggle = true;                                         
    $.each( text, function( key , value ){
      console.log(value);   //Value is empty                    
    });

I know the problem is in accessing the variable 'text' but I can't able to sort it off .. Thanks in advance

5
  • 3
    text is not an array, it's a string. Commented May 27, 2014 at 13:47
  • 1
    You are setting text to an array, then you are throwing out that array and replacing text with a string. Commented May 27, 2014 at 13:48
  • And actually, in this case, the value is not empty - it is a 'T' Commented May 27, 2014 at 13:50
  • 1
    Please stop using alert() for trouble-shooting. Spread the word. Commented May 27, 2014 at 13:53
  • 1
    @JayBlanchard: "Please stop using alert()" FIFY Commented May 27, 2014 at 13:54

1 Answer 1

3

Try to split out the text with empty character and then iterate the resultant array,

$.each( text.split(''), function( key , value ){
   alert(value);                 
});

DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.