Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换div中的文本_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 替换div中的文本

Javascript 替换div中的文本,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何删除文本 关于我们和在 我试着去做 $(“div.second”)。替换为(“”) 但是它需要一些课程。。但我只是想了解一下我们我该怎么做 <div class="footer-block"> <div id="custom-menu-wizard-2"><h4>About Us</h4><div class="menu-footer_about_menu-container"> <ul id="menu-footer_abo

如何删除文本

关于我们

我试着去做

$(“div.second”)。替换为(“”)

但是它需要一些课程。。但我只是想了解一下我们
我该怎么做

<div class="footer-block">
<div id="custom-menu-wizard-2"><h4>About Us</h4><div class="menu-footer_about_menu-container">
<ul id="menu-footer_about_menu" class="menu-widget  " data-cmwv="3.1.3"><li id="menu-item-1054"><a href="http://projects.bizarresoftware.in/innomations/?page_id=38&amp;tab=1">Corporate Profile</a></li>
<li id="menu-item-1055" class="menu-item menu-item-type-custom menu-item-object-custom cmw-level-1 menu-item-1055"><a href="http://projects.bizarresoftware.in/innomations/?page_id=38&amp;tab=2">Vision</a></li>
<li id="menu-item-1056" class="menu-item menu-item-type-custom menu-item-object-custom cmw-level-1 menu-item-1056"><a href="http://projects.bizarresoftware.in/innomations/?page_id=38&amp;tab=3">Mission</a></li>
<li id="menu-item-1057" class="menu-item menu-item-type-custom menu-item-object-custom cmw-level-1 menu-item-1057"><a href="http://projects.bizarresoftware.in/innomations/?page_id=38&amp;tab=4">Core Team</a></li>
</ul>
</div>
</div>

关于我们
注意:


我不能简单地用替换,因为它将替换页面中的所有
h4
。。如何遍历
页脚块
,然后进行替换。

$(“.footer block h4”).html(“”)
$(“.footer block h4”).html(“”)

您可以使用html的回调函数:

$('#custom-menu-wizard-2 h4').html(function(){
  return "<a href='#aboutus'/>" +  $(this).html() + "</a>");
});
$('#custom-menu-wizard-2h4').html(函数(){
返回“”);
});

您可以使用html的回调函数:

$('#custom-menu-wizard-2 h4').html(function(){
  return "<a href='#aboutus'/>" +  $(this).html() + "</a>");
});
$('#custom-menu-wizard-2h4').html(函数(){
返回“”);
});
试试看

$( "#custom-menu-wizard-2 h4:first-child").replaceWith( "<h4><a href='#aboutus'>About Us</a></h4>" );
$(“#custom-menu-wizard-2h4:第一个子项”)。替换为(“”);
试试看

$( "#custom-menu-wizard-2 h4:first-child").replaceWith( "<h4><a href='#aboutus'>About Us</a></h4>" );
$(“#custom-menu-wizard-2h4:第一个子项”)。替换为(“”);
$('#自定义菜单向导-2')。查找('h4')。删除();
$('#custom-menu-wizard-2').html('';
考虑到“
#custom-menu-wizard-2

$(“#custom-menu-wizard-2”)中没有其他元素或文本。查找('h4')。删除();
$('#custom-menu-wizard-2').html('';

考虑到“
#custom-menu-wizard-2
”中没有其他元素或文本,
replacetwith
函数没有错误,您只需放置正确的选择器
“#custom-menu-wizard-2 h4”

$('#custom-menu-wizard-2 h4')。替换为(“”)

关于我们

使用
ReplaceWith
功能没有错误,您只需将正确的选择器
'#custom-menu-wizard-2 h4'

$('#custom-menu-wizard-2 h4')。替换为(“”)

关于我们
您可以使用wrapInner()jsfiddle:

$('.footer block h4').wrapInner(“”)
您可以使用wrapInner()jsfiddle:

$('.footer block h4').wrapInner(“”)

您需要使用
替换为

$('#custom-menu-wizard-2 h4')。替换为(“”);

您需要使用
替换为

$('#custom-menu-wizard-2 h4')。替换为(“”);
$(“.footer block h4”)。替换为(“”);
$(“.footer block h4”)。替换为(“”);
$(“div#custom-menu-wizard-2h4”)。替换为(“”);
$(“div#custom-menu-wizard-2 h4”)。替换为(“”);

您不能直接在#custom-menu-wizard-2下选择h4并使用replaceWizard。您不能直接在#custom-menu-wizard-2下选择h4并使用replaceWizard。您的第二行将删除$('#custom-menu-wizard-2')中的所有内容,只需在其中添加一个链接。您的第二行将删除$('#custom-menu-wizard-2'中的所有内容)只需在Mine is div中添加一个链接,将脚本替换为
我的is div,将脚本替换为
一般来说,如果答案中包含对代码意图的解释,那么答案会更有帮助,为什么不引入其他人就解决了问题。(这篇文章至少有一位用户标记过,大概是因为他们认为应该删除一个没有解释的答案。)–一般来说,如果答案中包含对代码意图的解释,以及在不介绍其他人的情况下解决问题的原因,那么答案会更有帮助。(这篇文章至少有一位用户标记,大概是因为他们认为应该删除没有解释的答案。)
$( '#custom-menu-wizard-2 h4' ).replaceWith( "<h4><a href='#aboutus'>About Us</a></h4>" );
 $( ".footer-block h4" ).replaceWith( "<a href='#aboutus'>About Us</a>" );
 $("div#custom-menu-wizard-2 h4").replaceWith('<h4><a href=\'#aboutus\'>About Us</a></h4>');