我有以下由 C# 生成的 HTML 代码:
<div class="more-news-items" id="@id">
<p>Content goes here</p>
<div style="text-align:center">
<button class="newsfeed-hide">TOON MINDER</button>
<button class="newsfeed-more">TOON MEER</button>
</div>
</div>
我想隐藏
<p>Content goes here</p>
使用以下 Javascript 代码,但我想将按钮保留在 div 中。我将如何实现这一目标,如果不可能,我该如何实现?
$(document).ready(function () {
div.find('.newsfeed-hide').click(function () {
$('.more-news-items').html('');
});
});
最佳答案
尝试
$(document).ready(function () {
$('.newsfeed-hide').click(function () {
$('div.more-news-items').children('p').hide();
});
});
或
$(document).ready(function () {
$('.newsfeed-hide').click(function () {
$('div.more-news-items p').hide();
});
});
或
$(document).ready(function () {
$('.newsfeed-hide').click(function () {
$(this).parent().siblings('p').hide();
});
});
关于javascript - 使用 .html() 隐藏 <div> 中的内容而不隐藏内部 <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291190/