使用Jquery设置点击时ul的高度
实际上,我有一个ul,它使用css设置为特定的高度。我试图在单击div元素时设置ul的高度。这是我的密码 HTML: 我错过什么了吗使用Jquery设置点击时ul的高度,jquery,Jquery,实际上,我有一个ul,它使用css设置为特定的高度。我试图在单击div元素时设置ul的高度。这是我的密码 HTML: 我错过什么了吗 这是的ul是下一个兄弟姐妹,因此,您只需使用.next(),之后不需要使用.find() $(this).next('ul').css('height', '10px'); 演示: 在您的情况下,您试图查找一个ul元素,该元素是所单击的的下一个兄弟的后代。嘿使用在下一个之后不查找,因为 当我们使用next()时,它将到达ul 因此,现在不需要查找ul $(doc
这是的
ul
是下一个兄弟姐妹,因此,您只需使用.next(),之后不需要使用.find()
$(this).next('ul').css('height', '10px');
演示:
在您的情况下,您试图查找一个ul
元素,该元素是所单击的的下一个兄弟的后代。嘿使用在下一个之后不查找,因为
当我们使用next()时,它将到达ul
因此,现在不需要查找ul
$(document).ready(function() {
$('.hey').click(function(){
$(this).next('ul').css('height','10px');
});
});
是。实际上,next()将找到下一个元素,并在其中搜索ul检出
<div class="hey">Click me</div>
<div>
<ul style="height:100px">My Height</ul>
</div>
点击我
我的身高
它的工作检查您可以通过行高
CSS属性使用
选中此项
jQuery
HTML
希望这对你有帮助 没有html,不知道这是什么,我们就无法帮助youThanks Arun。工作很好。
$(document).ready(function() {
$('.hey').click(function(){
$(this).next('ul').css('height','10px');
});
});
<div class="hey">Click me</div>
<div>
<ul style="height:100px">My Height</ul>
</div>
$(document).ready(function() {
$('.hey').click(function(){
alert($('ul').css('height'));
$(this).siblings('ul').css('height','10px');
alert($('ul').css('height'));
});
});
$(document).ready(function() {
$('.hey').click(function(){
$('div').next().css('line-height','10px');
});
});
<div class="hey">Click me</div>
<ul>My Height</ul>
ul {
border:1px solid #FF0000;
line-height:100px;
}