I have the following structure:
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?
I have the following structure:
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?
これを試して、
$( "#navbar li a.arrow" ).click(function() {
$(this).next('ul').css("display", "block");
});
closest()
最も近い親オブジェクトを選択します。使用する必要がありますnext()
ここで使用.next()
:
$(this).next().css("display", "block");
が常に下.next()
にある場合に使用できますul
.arrow
$(this).next()
closest()
最も近い一致する親要素を選択するために使用されます。兄弟を選択するにはnext()
:
$( "#navbar li .arrow" ).click(function() {
$(this).next('ul').css("display", "block");
});