tags:

views:

46

answers:

3

I want to check if my row id is within in an array. If I set a fixed value to myindex it works but as it is below it always returns the FALSE value.Thank you.

$('#stripeMeSubSubCat tr').each(function(){
    myindex = $.trim($(this).closest("tr").attr("id"));

    var array = [ 0, 52, 53 ];

    alert(myindex);
    alert(array);

    if ((jQuery.inArray(myindex, array)) == -1) {
        var equal = "FALSE";
    } else {
        var equal = "TRUE";
    }
    alert(equal); 
});
+6  A: 

added parseInt() to myindex and fixed the problem.

Looking at the JQuery code reveals that inArray uses === as a comparison operator. Don't know why you would want use JQuery functionality for this though, since JavaScript has indexOf built-in.
Anders
+2  A: 

You need to convert the string variable ( myindex ) into int using parseInt function ..

dejavu
A: 
var  myindex = +$.trim($(this).closest("tr").attr("id"));
J-P