replaceWith( content )
用‘content’的内容替换匹配元素集合
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button").click(function () {
$(this).replaceWith("<div>" + $(this).text() + "</div>");
});
});
</script>
<style>
button { display:block; margin:3px; color:red; width:200px; }
div { color:red; border:2px solid blue; width:200px;
margin:3px; text-align:center; }
</style>
</head>
<body>
<button>First</button>
<button>Second</button>
<button>Third</button>
</body>
</html>
$(this).replaceWith("<div>" + $(this).text() + "</div>");
当点击按钮的时候,将匹配元素集合内容用新内容‘"<div>" + $(this).text() + "</div>"’替换。
分享到:
相关推荐
本文实例讲述了jQuery中replaceWith()方法用法。分享给大家供大家参考。具体分析如下: 此方法将所有匹配的元素替换成指定的HTML或DOM元素。 需要注意的是此方法是追加内容,也就是原来的内容还在。 特别说明: HTML...
replaceWith(content|fn) replaceAll(selector) 删除 empty() remove([expr]) detach([expr]) 复制 clone([Even[,deepEven]]) 筛选 过滤 eq(index|-index) first() last() hasClass(class) filter...
6.4.1 replaceWith(content) 103 6.4.2 replaceAll(selector) 104 6.5 删除 104 6.5.1 empty() 104 6.5.2 remove([expr]) 105 6.5.3 detach([expr]) 106 6.6 复制 106 6.6.1 clone() 106 6.6.2 clone(true) 107 7. ...
$.replaceWith( content ), .replaceWith( fn ) $.replaceAll( selector ) Removing $.detach( [selector] ) $.empty( ) $.remove( [selector] ) Copying $.clone( [withDataAndEvents], [deepWithDataAndEvents] )...
jQuery详细教程,讲解很透彻, 一. jQuery 语法实例 $(this).hide() 演示 jQuery hide() 函数,隐藏当前的 HTML 元素。...<p>This is a paragraph with little content. <p>This is another small paragraph. ...
replaceWith(content|fn) replaceAll(selector) 删除 empty() remove([expr]) detach([expr]) 复制 clone([Even[,deepEven]]) 筛选 过滤 eq(index|-index) first() last() hasClass(class) filter...
本文实例讲述了jQuery替换节点的方法。分享给大家供大家参考,具体如下: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title></title> ...
replaceWith(content) replaceAll(selector) 删除 empty() remove([expr]) 复制 clone() clone(true) 筛选 过滤 eq(index) hasClass(class) filter(expr) filter(fn) is(expr) map(callback) not(expr) ...
replaceWith(content) replaceAll(selector) 删除 empty() remove([expr]) 复制 clone() clone(true) 筛选 过滤 eq(index) hasClass(class) filter(expr) filter(fn) is(expr) map(callback) not(expr) ...
get(index) index(subject) 数据缓存 data([name] , [value]) data(obj) removeData(name) $.data([el], [key], [val]) 队列控制 queue(name ,[cb|queue]) dequeue(name) clearQueue([queueName]) 插件机制 jQuery....
本文实例讲述了jQuery中replaceAll()方法用法。分享给大家供大家参考。具体分析如下: 此方法用匹配元素去替换指定的内容。 replaceAll()方法的作用和replaceWith()方法是完全一样的。 语法结构: 代码如下:$...
}) $("p").replaceWith("你最喜欢的水果是</strong>"); 将元素的HTML代码改成 选择你最喜欢的水果。">你最喜欢的水果是?</strong></p> var p_html=$("p").html(); alert(p_html) var p_text=$("p").text(); alert...