[英]Find and replace in div tag using jQuery?
I have div tag with css class name. 我有CSS类名称的div标签。 div class name is same in for other div tags.
div类名称与其他div标签相同。 I want findout a text inside the div tag with css class name and replace with next text
我想在div标签中找到具有CSS类名称的文本并替换为下一个文本
<div class="ms-listdescription">
Share a document with the team by adding it to this document library.
</div>
with new text 带有新文字
<div class="ms-listdescription">
Share a document with the team by adding it to this document library
<br/> new text.
</div>
Update: This is very simple just find text "Share a document with the team by adding it to this document library" in if it is matches text then only append new text with existing text. 更新:这很简单,只要找到文本“通过与团队共享文档,将其添加到此文档库中”即可,如果该文本与文本匹配,则仅在现有文本后附加新文本。
var txt = $("div.ms-listdescription").html();
if( txt == "Share a document with the team by adding it to this document library" ) {
$("div.ms-listdescription").html( txt + "<br/>new text" );
}
see above -- is this what you want? 见上文-这是您想要的吗?
I am not sure I completly understand your question but I think you want the jquery .append() function 我不确定我是否完全理解您的问题,但我认为您需要jquery .append()函数
your code would look like this 您的代码如下所示
$('.ms-listdescription').append('<br/> NEWTEXT');
This is better than the . 这比更好。 html() because it does not clear the inside it just adds to the end of the stuff in the div.
html(),因为它不清除内部内容,只是将其添加到div中的内容的末尾。
You can check that it contains text by using :contains()
. 您可以使用
:contains()
检查其中是否包含文本。
$(".ms-listdescription:contains('Share a document with the team by adding it to this document library')")
.html(
$(".ms-listdescription").html() + $("<br>new text")
);
$('.ms-listdescription').each(function(){
if ($(this).html() === "Share a document with the team by adding it to this document library") {
$(this).append('<br/>new text');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.