Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

【jQuery】eachメソッドで各要素にfunctionを適用する

ソースコード

eachメソッドでjQueryオブジェクトの各要素にfunctionを適用します。

<body>
<div id="days"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<script type="text/javascript">
    (function ($) {
        var days = {Sunday: 0, Monday: 1, Tuesday: 2, Wednesday: 3, Thursday: 4, Friday: 5, Saturday: 6};
        $.each(days, function (key, value) {
            $('#days').append('<li>' + key + ' (' + value + ')</li>');
        });
    })(jQuery);
</script>
</body>

レンダリング