我的网页上有以下文字
JQuery的语法旨在使导航文档,选择DOM元素,创建动画,处理事件和开发Ajax应用程序变得更加容易。 jQuery还为开发人员提供了在JavaScript库之上create plug-ins的功能。这使开发人员能够create abstractions进行低级交互和动画,高级效果以及高级,可主题化的小部件。 jQuery库的模块化方法允许创建功能强大的动态网页和Web应用程序。
HTML结构如下所示
<div id=“mycontainer”>
JQuery's syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, a. jQuery also provides capabilities for developers to <a href=“http://jquery.com”>create plugins</a> on
top of the JavaScript library. This enables developers to <a href=“http://www.jquery.com”>create abstractions</a> for low-level interaction and animation, advanced effects and high-level, theme-able widgets. The modular approach to the jQuery library
allows the creation of powerful <b>dynamic</b> web pages and web applications.
</div>
现在我想要隐藏div id #mycontainer下的所有文本,并且只使用jquery显示下面给出的锚标签。我尝试使用text(),clone()等几个选项但是无法成功。请帮我搞定工作脚本
<div id=“mycontainer”>
<a href=“http://www.jquery.com”>create plugins</a>
<a href=“http://www.jquery.com”>create abstractions</a>
</div>
答案 0 :(得分:0)
这将实现您的目标: -
$(function(){
$('#mycontainer').html($('#mycontainer').find('a'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="mycontainer">
JQuery's syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, a. jQuery also provides capabilities for developers to <a href="http://jquery.com">create plugins</a> on
top of the JavaScript library. This enables developers to <a href="http://www.jquery.com">create abstractions</a> for low-level interaction and animation, advanced effects and high-level, theme-able widgets. The modular approach to the jQuery library
allows the creation of powerful <b>dynamic</b> web pages and web applications.
</div>