- スタイル設定・取得
- css : CSS取得
- addClass, removeClass : クラスの設定・削除
$('p').css('color','red');
console.log($('p').css('color'));
$('p').addClass('myStyle');
console.log($('a').attr('href'));
$('a').attr('href', 'http://google.co.jp');
console.log($('a').data('sitename'));
- タグの中身操作・取得
- text, html
- val
- remove(要素削除), empty
$('p').text('just changed');
$('p').html('<a href="">click me !</a>');
console.log($('input').val());
$("p").empty();
- 要素を追加する
- before, after
- insertBefore, insertAfter
- prepend, append
- prependTo, appendTo
var li = $('<li>').text('just added');
$('ul > li:eq(1)').before(li);
li.insertBefore($('ul > li:eq(1)'));
$('ul').prepend(li);
li.prependTo($('ul'));
- エフェクト
- hide, show
- fadeOut, fadeIn
- toggle
$('#box').hide(800);
$('#box').fadeIn(800);
$('#box').toggle(800);
$('#box').fadeOut(800, function(){
alert("done!");
});
- イベント
- click
- mouseover, mouseout, mousemove
$('#box').click(function(){
alert('click!!!');
});
$('#box')
.mouseover(function(){
$(this).css('background','green');
})
.mouseout(function(){
$(this).css('background','red');
})
.mousemove(function(e){
$(this).text(e.pageX);
});
$('name')
.focus(function(){
$(this).css('background','red');
})
.blur(function(){
$(this).css('background','white');
});
$('#members').change(function(){
alert('changed!!!');
});
$('button').click(function(){
var p = $('<p>').text('vanish!').addClass('vanish');
$(this).before(p);
});
$('body').on('click', '.vanish', function(){
$(this).remove();
});