views:

21

answers:

1

I want to get all labels inside a div, the blow piece of code works in Firefox and not working IE. Any idea. Thanks in advance.

<div id='discounts'>
  <label id="discount1"> discount 1</label>
  <label id="discount2"> discount 2 </label>
  <input type="text" id="discountmisc"  value="" />    
</div>

var selectLabels = {

    getLabels: function() {
        $('#discounts > label').each(function(index, item) {
            alert(index + $(item).attr('id'));
        });
    }
};

selectLabels.getLabels();
+2  A: 

Are you wrapped in DOM Ready functions? i.e.

$(function () {
    var selectLabels = {
        getLabels: function() {
            $('#discounts > label').each(function(index, item) {
                alert(index + $(item).attr('id'));
            });
        }
    };

    selectLabels.getLabels();
});

or alternately:

var selectLabels = {
    getLabels: function() {
        $('#discounts > label').each(function(index, item) {
            alert(index + $(item).attr('id'));
        });
    }
};

$(selectLabels.getLabels);

or finally (because you don't care about the return value):

var selectLabels = {
    getLabels: function() {
        $(function () {
            $('#discounts > label').each(function(index, item) {
                alert(index + $(item).attr('id'));
            });
        });
    }
};

selectLabels.getLabels();

Tell me, and if so, I'll change my answer.

Dan Beam
that's enough alternatives, eh? haha, :P
Dan Beam