LoginSignup
3
6

More than 5 years have passed since last update.

【jQuery】基本的なメソッドなど

Last updated at Posted at 2018-05-01

表示/非表示

//表示
$('セレクタ').show();
//表示 時間指定
$('セレクタ').show(2000);
//非表示
$('セレクタ').hide();
//非表示 時間指定
$('セレクタ').hide(1500);

スライド表示/非表示

//スライド表示
$('セレクタ').slideUp();
//スライド表示 速度指定
$('セレクタ').slideUp(slow);
//スライド非表示
$('セレクタ').slideDown();
//スライド非表示 速度指定
$('セレクタ').slideDown(slow);

クリックイベント

$('セレクタ').click(function(){
 $('セレクタ').メソッド();
});
//thisで対象を絞り込む
$('セレクタ').click(function(){
 $(this).メソッド();
});

hoverイベント

$('セレクタ').hover(function(){
 //hover時
 $('セレクタ').メソッド();
},
function(){
//hover外した時
 $('セレクタ').メソッド();
})

CSSの変更

$('セレクタ').css('プロパティ名','');

文字の変更

$('セレクタ').text('書き換える文字');

htmlの挿入

$('セレクタ').html('挿入するHTML');

クラスの設定/クラスを外す

//クラスの設定
$('セレクタ').addClass('クラス名');
//クラスを外す
$('セレクタ').removeClass('クラス名');

クラス持っているか? true falseを返す

//クラスの設定
$('セレクタ').hasClass('クラス名');
//イメージ
if($('p').hasClass('test')){
  $(this).hide();
} else {
 $(this).show();
}

変数の定義

var $変数名 = $('セレクタ');

メソッドチェーンで指定  一つのセレクタに対して複数のメソッドを指定

$('セレクタ').html('挿入するHTML').color('プロパティ','').fadeOut();
3
6
2

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
6