LoginSignup
3
3

More than 5 years have passed since last update.

jQueryあれこれ

Last updated at Posted at 2018-03-27

何度も調べていて、馬鹿らしいのでまとめた

要素の取得方法

// id
$('#hoge').val()

//class
$('.hoge').val()

// name
$('[name=hoge]').val()

// data属性
$('[data-***=hoge]').val()

ループ


var array = [];
$.each(array, function(index, value)) {
    // ループを抜け出す時(break)
    return false;

    // 処理をスキップする時(continue)
    return true;
};

//targetContent: .Class #id [data-***=hoge] etc...
targetContent.each( function( index, element ) {
    // ループを抜け出す時(break)
    return false;

    // 処理をスキップする時(continue)
    return true;
});

イベントバインド


//event : click,change etc...
//targetContent: .Class #id [data-***=hoge] etc...

// 動的に追加された項目のイベントも検知可能
$(document).on('event', 'targetContent', function () {
    // あれこれ
});

// 動的に追加された項目のイベントは「検知不可」
$('targetContent').on('event' , function () {
    // あれこれ
});


3
3
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
3
3