filterメソッドで下記のhtmlの一部を抽出したい。
<div data-test="hoge1">foo1</div> <div data-test="hoge2">foo2</div> <div data-test="hoge1">foo1</div>下のようにscriptを組んでも抽出できなかった。
むしろエラー。
jQuery(function($){ console.log($('div').filter('data-test="hoge1"')) });jQuery - filter element based on .data() key/value
を読んで、下のようにしたら取得できた。
jQuery(function($){ console.log($('div').filter('[data-test="hoge1"]')) });
0 コメント:
コメントを投稿