:not( )に関して – jquery

 

環境

  • :not( )
  • js
  • Javascript
  • html
  • html5
  • HTML
  • HTML5
  • jquery
  • jQuery

概要

指定したセレクタ「以外」の要素を選択
指定したセレクタのみ除外

実装

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
        <script type="text/javascript">

            $(function () {
                $("button").click(function(){
                    $("div:not(.sample)").css("background-color","red");
                });
            });

        </script>
        <style type="text/css">
        <!--
            div{
                color:fff;
                width:300px;
                margin:15px;
                padding:5px;
                background-color:#09C;
            }
        -->
        </style>
    </head>

    <body>
        <div class="tes">class属性がsampleのdiv</div>
        <div>div</div>
        <div class="sample">class属性がtestのdiv</div>
        <div>div</div>
        <button>CLICK</button>
    </body>
</html>

参考

:not( )

実行

on.gif

藤沢瞭介(Ryosuke Hujisawa)
  • りょすけと申します。18歳からプログラミングをはじめ、今はフロントエンドでReactを書いたり、AIの勉強を頑張っています。off.tokyoでは、ハイテクやガジェット、それからプログラミングに関する情報まで、エンジニアに役立つ情報を日々発信しています!

未整理記事