LoginSignup
75
77

More than 5 years have passed since last update.

jQueryのeachメソッド

Last updated at Posted at 2018-07-01

HTML要素に対する繰り返し

<ul>
  <li>Ruby</li>
  <li>JavaScript</li>
  <li>PHP</li>
</ul>
  $('li').each(function(index, element){
    console.log(index + ':' + $(element).text());
  })

以下のように出力される。

0:Ruby
1:JavaScript
2:PHP

配列・オブジェクトに対する繰り返し


var array = ['Rails', 'jQuery', 'FuelPHP'];

$.each(array, function(index, value){
  console.log(index + ':' + value);
})

以下のように出力される。

0:Rails
1:jQuery
2:FuelPHP

参考

【jQuery入門】2種類のeach()による繰り返し処理まとめ!

[【jQuery】複数の要素に対して繰り返し処理をする(each・for)!]
(http://www.task-notes.com/entry/20140725/1406216933)

75
77
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
75
77