Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/theme.php on line 623

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/custom_posts/custom_posts.php on line 22

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 46

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 67

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 75

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 92

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiRender.php on line 70

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 181

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 538

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 695

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 1087

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112
[js] jQueryセレクタ「:visible」と「:hidden」のこと | おれせか
おれせか

なんかそれっぽいのをうにうに。

jQuery1.3.2から「:visible」と「:hidden」セレクタの仕様が変わって、cssでvisibility:hiddenしただけの要素は「:visible」として扱われるようになった。

jQuery1.3.1以前
要素のCSSを見て、"display"が"none"ではなく、"visibility"が"hidden"ではなく、input要素であればtype属性が"hidden"でないこと

jQuery1.3.2以降
ブラウザがoffsetWidthおよびoffsetHeightにゼロより大きい値を返すこと

この変更により、対象要素のdisplayが"none"の場合はもちろん、親要素のdisplayが"none"であったり、要素のwidthやheightがゼロであった場合なども、":hidden"として検出されるようになりました。

http://semooh.jp/jquery/cont/doc/release_1.3.2/

でもこの仕様だと「visibility:hiddenだって見えないのにhiddenじゃねーのかよ」という違和感があるので、visibility:hidden時にはhidden判定される用のセレクタを用意してみた。
#既存の「:visible」「:hidden」は、それはそれで使う場合もあるだろうから書き換えではなく追加。

参考:JavaScript++かも日記: 【jQuery】自作セレクタの追加

$.extend($.expr[':'], {
      _visible: function(elem){
        if($.expr[':'].hidden(elem)) return false;
        if($.curCSS(elem, 'visibility') == 'hidden') return false;
        return true;
    }
    , _hidden: function(elem){
        if($.expr[':'].hidden(elem)) return true;
        if($.curCSS(elem, 'visibility') == 'hidden') return true;
        return false;
    }
});

これで以下のようなコードで使えるように。

$('p:_visible') //表示されているpタグ。
$('p:_hidden') //表示されていないpタグ。
PAGETOP
PAGETOP
PAGETOP

Comments (9)

それは多くの情報が含まれているように私は、私にとって非常に有用なこの記事を見つけることが嬉しいです。

[2013/05/21 (火) 12:30]

not to say that employers aren’t looking for them; they are. But the numbers show that old-guard certifications are still the ones employers l

[2015/08/13 (木) 16:35]

macだとコピーとペーストのコマンドがそれぞれ『pbcopy』と『pbpaste』なので、
変換したい文字列をコピーして、

[2015/09/16 (水) 13:06]

l直書きでネスト作るこ

[2015/10/13 (火) 17:13]

画像の一部を任意のサイズに切り抜くjQueryプラグイン作ったー。
ひとまず、IE6~、Firefox、Google Chromeでは動作確認できました

[2016/01/06 (水) 18:10]

フラグとほぼ同じですが, 各ループの最後に変数 $_ の値を出力するようになります。

[2016/01/07 (木) 11:00]

宝のスーパーコピーめでたい(ミュウミュウ)。

[2016/01/15 (金) 17:44]

jQuery1.3.2から「:visible」と「:hidden」セレクタの仕様が変わって、cssでvisibility:hiddenしただけの要素は「:visible」として扱われるようになった。

[2016/06/20 (月) 12:20]

宝のスーパーコピーめでたい(ミュウミュウ)。

[2016/06/27 (月) 18:39]
PAGETOP

Comment Form

PAGETOP

Trackbacks (0)

トラックバックはありません。

PAGETOP

Trackback URL

PAGETOP

Search