index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DOM 节点操作</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="demo.js"></script> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <div class="box">节点</div> <div>节点</div> </body> </html>
demo.js
$(function(){ //$('div').wrap('<strong class="bbb"></strong>'); //$('div').wrap('<strong/>'); //$('div').wrap('<strong>onestopweb</strong>'); //$('div').wrap('<strong><em></em></strong>'); //$('div').wrap($('strong').get(0)); //$('div').wrap(document.createElement('strong')); /* $('div').wrap(function(index){ return '<strong>'+index+'</strong>'; }); */ //$('div').wrap('<strong><em></em></strong>'); //$('div').unwrap(); //$('div').unwrap(); //$('div').wrap('<strong><em></em></strong>'); //$('div').wrapAll('<strong><em></em></strong>'); //$('div').wrapAll(document.createElement('strong')); //$('div').wrapInner('<strong><em></em></strong>'); //$('div').wrapInner(document.createElement('strong')); /* $('div').wrapInner(function(index){ return '<strong>'+index+'</strong>'; }); */ $('div').click(function(){ alert('oneStopWeb.cn'); }); //$('div').clone().appendTo('body'); //$('div').clone(true).appendTo('body'); //$('div').remove('.box'); //$('div.box').remove(); //alert($('div').remove().get(0)); //$('div').remove().appendTo('body'); //$('div').detach().appendTo('body'); //$('div').empty(); //$('div').replaceWith('<span>DOM</span>'); $('<span>DOM</span>').replaceAll('div'); });