使用jQuery在标记后隐藏文本 [英] Hide Text after a tag using jQuery

查看:87
本文介绍了使用jQuery在标记后隐藏文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在标记后隐藏某些文字。

I would like to hide certain text after a tag.

我的HTML是:

<div class="listing_detail col-md-4"><strong>Living Room:</strong> Yes</div>
<div class="listing_detail col-md-4"><strong>Kitchen:</strong> No</div>

jQuery:

$($('.listing_detail strong')[0].nextSibling).wrap('<span style="display:none"></style>');

上面的jQuery只删除第一个元素中的文本,而不是两者。

The jQuery above only removes the text from the first element and not both.

如何修改它,以便从两个元素中删除文本。

How can I modify it so that it removed the text from both elements.

小提琴

推荐答案

只需考虑循环遍历元素并隐藏通过为每个< strong> 元素添加下一个兄弟 each() 函数:

Just consider looping through your elements and hiding the next sibling for each <strong> element via the each() function :

// Loop through each strong element
$('.listing_detail strong').each(function(){
  // Find it's next sibling and wrap it
  $(this.nextSibling).wrap('<span style="display:none"></style>');
});

示例

$('.listing_detail strong').each(function(){
  $(this.nextSibling).wrap('<span style="display:none"></style>');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="listing_detail col-md-4"><strong>Living Room:</strong> Yes</div>
<div class="listing_detail col-md-4"><strong>Kitchen:</strong> No</div>

这篇关于使用jQuery在标记后隐藏文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆