前端學習(二十)jquery屬性(筆記)
jq裏面操作屬性的方法:
設置屬性:
設置一個:
$(this).attr(‘src‘,‘img/pic2.jpg‘);
設置一組:
$(this).attr({src:‘img/pic2.jpg‘,title:‘不好看的圖‘,id:‘aaa‘});
獲取屬性:
alert($(this).attr(‘title‘));
刪除屬性:
$(this).removeAttr(‘src‘);
-==------------------------------------------=-
dom操作!
創建
添加
$(‘<h2>h2h22h2h2h2h2h2</h2>‘).appendTo(‘#box‘);
$(‘<h2>h2h22h2h2h2h2h2</h2>‘)---創建元素!
.appendTo(‘#box‘)---添加(默認#box子級的最後面)
.appendTo(父級)---父級內部後面!
.prependTo(父級)---父級內部前面!
.insertBefore(‘#box‘)----父級外部前面!
.insertAfter(‘#box‘)----父級外部後面!
刪除 ---remove
$(要刪除的元素).remove();---想刪除誰,就給誰remove‘
$(this).parent().remove();
當前的父級,刪除掉!
================================================
前端學習(二十)jquery屬性(筆記)