前端学习(二十)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();    

当前的父级,删除掉!

================================================

原文地址:https://www.cnblogs.com/wxiaoyu/p/9579330.html