0

特定の属性値を持つ要素が div タグ内に存在するかどうかを確認する方法。

例えば、

<div id='testdiv'>
    <a dir='hello' href='#' ></a>
</div>
<input type='button' id='btn' />

これが私のJqueryです。

$('#btn').click(function(){
   if(/*Here I need the condition to check whether, `a` tag with attribute `dir` with value `hello` is present inside `div` */)
   {
       alert(present);
   }
}

私はjQueryの初心者なので、親愛なる友人にアドバイスしてください。ありがとう。

4

3 に答える 3

0
$('#btn').click(function(){
   if($("div").find("a[dir=hello]").length == 1)
   {
       alert(present);
   }
}
于 2013-06-05T09:53:10.953 に答える
0
$('#btn').on('click', function(){
   if ( $('#testdiv a[dir="hello"]').length ) {
       alert(present);
   }
});
于 2013-06-05T09:53:32.283 に答える
0
$('#btn').on('click', function(){
       if ( $('#testdiv a').attr('dir') == 'hello' ) {
           alert('1111111');
       }
        else
            alert('222');
    });

このフィドルも参照してください

于 2013-06-05T10:02:22.000 に答える