【问题标题】:How to get the value of element with selector如何使用选择器获取元素的值
【发布时间】:2011-11-22 02:42:29
【问题描述】:

例子:

$(document).ready(function(){    

   height = $('#container-bottom:before').height();
   alert(height);

});

警报null(当然我知道值不是null)。

【问题讨论】:

  • 我们可以有一个包含一些示例 html 的 jsfiddle 吗?理论上 $.height 应该返回指定元素高度的无单位值。
  • @DravSloan 这是示例链接jsfiddle.net/EFXMf
  • 在...之前没有任何html元素
  • css 选择器:before 有什么原因吗?从 css 和 jquery select 中删除它似乎呈现相同的输出并给出预期值 (200)

标签: jquery css pseudo-element


【解决方案1】:

不幸的是,CCS 伪元素(如 :before:after)不是 DOM 的一部分(尽管它们被渲染得好像它们是一样) - 因此它们不能被 jQuery 操作。

见:Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery

【讨论】:

  • 谢谢,好吧,毕竟我必须使用真正的元素并且解决了问题,而不是伪元素 :before。
猜你喜欢
  • 2010-10-24
  • 2012-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-18
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多