javascript - 如果按钮包含 "sometext"如何隐藏 <li> - jQuery

标签 javascript jquery

enter image description here 正如您在图片中看到的,我有某种表格,我需要用 jQuery 隐藏整个“< div >”,称为表格,如果里面的按钮“< div >”表示“询问” 问题是我知道如何隐藏(实际上我希望它消失,我做到了),但是我不能做的部分是将button.ASKdiv.table

消失 div 的代码:$("div.table").css("display", "none");

我需要修改的代码:

<div class="_npuc5">
<div class="_f5wpw">
<a class="of_gvoze" href="Random_David" style="width: 30px; height: 30px;"><img class="_rewi8" src="http://es.horadeaventura.wikia.com/wiki/Archivo:AT_Icons_100x100_Jake.jpg">
</a>
<div class="_eryrc">
<div class="_2nunc">
<a class="_2g7d5w8" title="SOME TITLE HERE" href="ggggg.com/">RandomText</a>
</div>
<div class="Random_9mmn5">SOME TEXT HERE</div>
</div>
</div>
<div class="_mtnzs">
<span class="LLLL"><button class="askButton">ASK</button></span>
</div>
</div>

最佳答案

您可以使用 .filter() 来实现此目的功能:

$('#toggledisplay').click(function (){

  //get all the list items
  var lis = $('li');
  
  //with the filter function, I can 
  //specify custom conditions 
  //to the elements I want to do something with
  lis.filter(function (index){
    // "this" is the current li on the loop.
    //if the innertext of "this" equals "ask"
    //then yes, this is the li I want
    return $(this).text().trim() == "ASK";
  }).toggle();

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li>ASK</li>
  <li>nope</li>
  <li>hey</li>
</ul>

<br>

<button id="toggledisplay"> Togggle the display of "ASK" </button>

关于javascript - 如果按钮包含 "sometext"如何隐藏 <li> - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49859930/

相关文章:

javascript - 可以使用 Math.random() 生成密码重置 key 吗?

javascript - AngularJS/JQuery - 没有关联标签的表单输入

javascript - 通过用户名使用jquery获取图像

javascript - 使用ajax调用获取包含3个数组的json对象并将数组传递给javascript

javascript - 如何通过 Firefox 插件在网站上包含 JavaScript?

javascript - 如何使用JS/jQuery在一个页面的两个局部 View 之间切换?

javascript - 如何在 NightmareJS 中启用右键单击?

jquery - circlebar.js :11 Uncaught TypeError: $(. ..).find(...).circle 不是函数

jquery - 用于保留所选 "li"突出显示的 css/jquery

javascript - 单击时无法更改图像源