Skip to main content

Bug Tracker

Side navigation

#4180 closed bug (invalid)

Opened February 18, 2009 05:26AM UTC

Closed February 20, 2009 12:56AM UTC

Last modified March 14, 2012 02:47PM UTC

jQuery.each() bug on Internet Explorer when used on strings

Reported by: gaby Owned by:
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: each string Cc:
Blocked by: Blocking:
Description

Hi,

if you use the jQuery.each() on a string, it will not yield the same results on IE and the rest of the browsers..

example.

var str= 'abc';
jQuery.each(str, function(index, item)
    {
        $('#display').append('<br />' + idx + ' : ' + item);
    });

after this the #display will have on all browsers but IE

0:a
1:b
2:c

on IE it will be

0:undefined
1:undefined
2:undefined

some thing happens if the callback is without parameters and we use 'this'

var str= 'abc'; 
jQuery.each(str, function() 
{ 
 $('#display').append('<br />' + item); 
});

all browsers will display the letters one-by-one, but IE will display undefined for each letter (so the loop is working but it messes up the data)

Shouldn't it work, since a string is an array ?

regards

Attachments (0)
Change History (1)

Changed February 20, 2009 12:56AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

The

string[index]
syntax for obtaining a character isn't standard Javascript. If you want to get a character in a standard way you should use
string.charAt(index)
.

If you want to use

$.each
on a string, you could split it into an one-char-per-element array beforehand with
string.split("")
.