views:

93

answers:

2

Hello all,

I make use of the following to find a string in a particular element, if it exists, tick a checkbox. This works great on Firefox but not internet explorer (8). I am having trouble finding why.

$.fn.searchString = function(str) {
   return this.filter('*:contains("' + str + '")');
};

var myID = $('div').searchString(files_array[i].substr(-4));

alert(myID);//[object object]

alert(myID.children());//[object object]

myID.children().attr('checked', true);//does not tick checkbox

alert(myID.children().attr('checked'));//undefined

Does IE not like the children() function?

Thanks all for any help

A: 

See http://dev.jquery.com/ticket/167 for this bug and the resolution. I am just learning jQuery. The resolution in the page I am referring ask us to use $("#method-download").get(0).checked = true; instead.

Kangkan
That is not necessary. Setting "checked" via "attr()" definitely works. I use it all over the place. You'll note that the bug you reference is 4 years old, and closed.
Pointy
Not my downvote but I agree with it, you definitely need to check the status of any bug you find in google, it's status and date makes it completely irrelevant.
Nick Craver
Thanks all. I am still learning. Actually I took interest in jQuery from a downvote only. Thanks to all.
Kangkan
+2  A: 

From MSDN, in reference to the "substr" function:

Remarks

If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of the string.

You're coming up with nothing from the original code that tries to set "myID".

Pointy
Just to add, for me, the substr seems to return the whole string if I put in a negative number but Firefox seems to understand what I am trying to do and it returns the last set of characters.
Abs
I wish I found this: http://rapd.wordpress.com/2007/07/12/javascript-substr-vs-substring/ - If start is negative, Internet Explorer returns the whole string. That’s wrong! IE should use the last character in the string.
Abs
That's funny - much as I despise IE, the MSDN documentation is *usually* very accurate. Well in any case my IE spider sense started tingling as soon as I saw that "substr(-4)" call.
Pointy