0

I have the following structure:

enter image description here

I tried this:

$( "#navbar li .arrow" ).click(function() {
  alert("worked");
  $(this).closest('ul').css("display", "block");
});

To select the ul element under .arrow. But nothing happen.

Any suggestions?

4

6 に答える 6

1

.closest ()メソッドは祖先要素をフェッチします。あなたの場合、要素ulの次の兄弟です.arrow

ここで. next()を使用する必要があります

$(this).next().css("display", "block");
于 2013-08-02T08:48:42.933 に答える
0

これを試して、

$( "#navbar li a.arrow" ).click(function() {
    $(this).next('ul').css("display", "block");
});
于 2013-08-02T08:54:43.813 に答える
0

closest()最も近い親オブジェクトを選択します。使用する必要がありますnext()

于 2013-08-02T08:49:57.780 に答える
0

ここで使用.next():

$(this).next().css("display", "block");
于 2013-08-02T08:51:12.923 に答える
0

が常に下.next()にある場合に使用できますul.arrow

$(this).next()
于 2013-08-02T08:48:46.727 に答える
0

closest()最も近い一致する親要素を選択するために使用されます。兄弟を選択するにはnext():

$( "#navbar li .arrow" ).click(function() {
    $(this).next('ul').css("display", "block");
});
于 2013-08-02T08:49:15.027 に答える