- 677 名前:デフォルトの名無しさん mailto:sage [2022/04/19(火) 02:49:01.33 ID:tGbJiwG70.net]
- >>644
jQuery で、id="test" 直下・子(a, c)と子孫(b)を取得した <div id="test"> <a href="a.html"></a> <div><a href="b.html"></a></div> <a href="c.html"></a> </div> $( function ( ) { function get_a( selector ) { return $( selector ).map( function( ) { return $( this ).attr( 'href' ); } ); } const children = get_a( '#test > a' ) const descendants = get_a( '#test a' ) console.log( children, descendants ) } ); 出力 ['a.html', 'c.html'] // 直下・子のみ ['a.html', 'b.html', 'c.html'] // 子孫
|

|