简体   繁体   English

用 jQuery 替换一个元素而不是另一个元素

[英]Replace a element instead another element by jQuery

I want replace a(or each) element(number) instead another element(number) in a class while running page.我想在运行页面时替换 class 中的一个(或每个)元素(编号)而不是另一个元素(编号)。

I try as following code but doesn't word true, what do i do?我尝试按照以下代码但不正确,我该怎么办?

DEMO: http://jsfiddle.net/yMnDt/演示: http://jsfiddle.net/yMnDt/

<div class="myGrid">
    1
    <p>
    123145
</div>​

$(".myGrid").clone().find('1').replaceWith( "8" );

If you want replace ONLY number 1 with 8 You need to do the follwing change如果你只想用 8 替换数字 1 你需要做以下更改

  • you need to put "1" in span tag你需要在 span 标签中加上“1”

please check the Below link请检查下面的链接

http://jsfiddle.net/8nrS2/1/ http://jsfiddle.net/8nrS2/1/

Is this what you want?这是你想要的吗? http://jsfiddle.net/yMnDt/7 http://jsfiddle.net/yMnDt/7

This uses replaceWith and no alert in the body http://jsfiddle.net/T2GAZ/这在正文中使用 replaceWith 并且没有警报http://jsfiddle.net/T2GAZ/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM