<div id="d">hello world!</div> <script> // append() - 在被选元素的结尾插入内容 // prepend() - 在被选元素的开头插入内容 // after() - 在被选元素之后插入内容 // before() - 在被选元素之前插入内容 $("<p>welcome</p>").appendTo($("#d")); 创建元素插入到div中 $("#d").append("<p>welcome</p>"); div中插入p元素 $("#d").prepend("<p>welcome</p>"); 插入div中前部 $("#d").after("<p>welcome</p>"); $("#d").before("<p>welcome</p>"); //insertAfter(),将元素追加到指定对象的后面(是同级关系) $("<p>welcome</p>").insertBefore($('#d')); //insertAfter(),将元素追加到指定对象的后面(是同级关系) $("<p>welcome</p>").insertAfter($("#d")); </script>
jquery 插入元素的方法
最新推荐文章于 2023-02-01 22:52:57 发布