3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryメソッド集メモ

Last updated at Posted at 2018-08-01

jQueryのいろんなメソッドをためていく

配列をソートして重複削除

$.unique(arr);

クッキー設定

// secureはhttps接続の場合のみcookieを送信
$.cookie(keyName, value, {expires : 365, path: /, domain: example.com, secure: true});

display:noneになっている要素を表示

$(selector).show();

要素の親要素を指定

$(selector).parent();
// 親要素を削除(自分の削除される)
$(selector).parent().remove();

配列内に指定した要素が存在するか

$.inArray(needle, arr);

フォームを指定

document.forms['myform'] // name=myformのフォーム
document.forms[0] // 最初のフォーム

セレクタ指定

element.querySelector('input[name=name]')
element.querySelector('input[name=name]').value // 指定した要素の値

要素の次の要素(兄弟要素全て)を取得

element.next()
element.next('.message1') // 次の要素の中でclass=message1の要素のみ取得

要素をフェードイン・フェードアウト

element.fadeIn()
element.fadeOut()
element.delay(1000).fadeOut() // 遅延実行

フォーム操作イベント

// キー操作イベント (全キー操作)
$('.target').on('keyup', function () {
     provision = $(this).val();
});

// checkeボックス等の変更イベント
$('.target').on('change', function () {
     provision = $(this).val();
});

// キーが押された時 (日本語入力や、文字の削除は検知できない)
$('.target').on('keypress', function () {
     provision = $(this).val();
});

後から追加された要素にイベント付与

// 親要素にonメソッドで付与したいイベントとターゲット要素を指定する
$('.parent').on('keyup', '.target', function () {
     provision = $(this).val();
});

DOM要素作成

// 要素作成
let textarea = $("<textarea class=\"text\">テキストエリアですわ</textarea>");

// カスタムデータ属性追加
textarea.attr('data-name', 'Yorinton');

フォーム要素にフォーカス

// テキストエリアにフォーカス
$('textarea').focus();

// フォーカスを外す
$('textarea').blur();

選択された部分を取得(Javascript)

selection = document.getSelection();

文字列に変換

Object.toString()
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?