开发者

jQuery to hide all classes that start with 'row' except ‘row2’ only when the parent class is viewContainerTop

开发者 https://www.devze.com 2022-12-11 00:04 出处:网络
A variation of this question... <div id=\"viewContainerTop\"> <div class=\"row1\"></div>

A variation of this question...

<div id="viewContainerTop">
  <div class="row1"></div>
  <div class="NotRow1"></开发者_如何学Cdiv>
  <div class="row2"></div>
  <div class="row2"></div>
  <div class="row2"></div>
  <div class="row3 first"></div>
  <div class="donthideme"></div>
  <div class="row4"></div>
  <div class="row5"></div>
</div>


If I understand you correctly, try this:

$('#viewContainerTop > [class^=row]').not('.row2').hide();

The > is optional--it excludes matching of any deeper objects that start with row.

Here's a live example that shows this, too (hit refresh to see the selector dim the desired elements).


Avoiding your direct question, but a better approach might be to create another class, say "canhide" and attach it to the divs you want to target. You should not be doing matches on partial class names.

<div id="viewContainerTop">
  <div class="canhide row1"></div>
  <div class="NotRow1"></div>
  <div class="row2"></div>
  <div class="row2"></div>
  <div class="row2"></div>
  <div class="canhide row3 first"></div>
  <div class="donthideme"></div>
  <div class="canhide row4"></div>
  <div class="canhide row5"></div>
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消