LoginSignup
10
12

More than 5 years have passed since last update.

jQueryで指定した文字列を含むidの要素を非表示にする

Last updated at Posted at 2014-07-02

超小ネタ。

自動で作ったようなtableタグに配列チックなidが振られてて、その中から指定した文字列を含む要素だけ非表示にする方法。

↓こんなHTMLから、 id_b を含む要素は非表示にする。

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>jQuery test</title>
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<table id="table_test" border="1">
  <tr>
    <th id="aaa[0].id_a">a</th>
    <th id="bbb[0].id_b">b</th>
    <th id="ccc[0].id_c">c</th>
  </tr>
  <tr>
    <td id="aaa[1].id_a">aaa</td>
    <td id="bbb[1].id_b">bbb</td>
    <td id="ccc[1].id_c">ccc</td>
  </tr>
</table>
</html>
// id_bを含む場合は *=
$("#table_test [id *= 'id_b']").hide();

// id_bで終わる場合は $=
$("#table_test [id $= 'id_b']").hide();
10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12