jquery创建一个新的节点对象(自定义结构/内容)的好方法

jq创建一个新的节点对象,这对一些自定义功能很有帮助,而且可以随意控制对象的结构与内容,何乐而不为呢,看到这里,相信有些朋友已经按耐不住了,好记下来为大家介绍实现方法,感兴趣的朋友可以了解下哦

 
<!DOCTYPE html> 
<html> 
<head> 
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<meta charset=utf-8 /> 
<title>JsBin-在线js/css调试工具</title> 
<!--[if IE]> 
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
<style> 
article, aside, figure, footer, header, hgroup, 
menu, nav, section { display: block; } 
</style> 
</head> 
<body> 
<p id="hello">Hello OSTools</p> 
</body> 
</html> 

JavaScript

 
//jq创建一个新的节点对象; 
//例如:<div id='mydiv' class='menu'></div> 
var objNewDiv = $('<div>',{'id':'mydiv','class':'menu'}); 
objNewDiv.html(123456); 
$('#hello').append(objNewDiv); 
console.log(objNewDiv);