可以使用jQuery根据其高度选择div吗?还是本教程错了? [英] Can jQuery be used to select a div based on its height? Or is the tutorial wrong?
本文介绍了可以使用jQuery根据其高度选择div吗?还是本教程错了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据其高度选择div
,如本教程所示,
jQuery选择.我无法使用它: jsbin示例.该行不起作用是:
I am trying to select a div
based on its height, as shown in this tutorial,
jQuery Selection. I cannot get it to work: jsbin example . The line not working is:
$('div[height=50px]').css('background-color', 'orange');
推荐答案
这是属性等于选择器,因此它将匹配的HTML是:
That's an attribute equals selector, so the HTML it would match is:
<div height="50px"></div>
您可以将其更改为:
$('div[style="height:50px"]').css('background-color', 'orange');
根据评论,以上内容在Internet Explorer中不起作用.请尝试以下操作:
According to comments, the above doesn't work in Internet Explorer. Try the following instead:
$('div').filter(function() {
return $(this).css('height') == '50px';
}).css('background-color', 'orange');
如果要匹配未使用属性指定的高度为50px的其他元素,请查看 .filter()
函数.
If you want to match other elements with a height of 50px not specified using an attribute, take a look at the .filter()
function.
这篇关于可以使用jQuery根据其高度选择div吗?还是本教程错了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文