问题:应用$(".price").hide();
的工作于已经呈现的元素,但是,当我通过javascript加载一个新模板时,价格类将是可见的。
问题:是一种在插入DOM时将样式应用于类的所有未来实例的方法。
示例:
$(".price").hide();
$('body').append('<div class="price">19.00</div>'); // this should be hidden.
发布于 2012-07-02 11:15:07
与其这样做,不如让切换开关修改容器元素以添加或删除类。
然后,有一个如下所示的CSS规则:
.hidePrice .price{
display:none;
}
切换按钮时,只需在容器元素上切换hidePrice类即可。
发布于 2012-07-02 10:27:09
我认为最好的解决方案是使用帮助类:
CSS
.helper{
display: none;
}
jQuery
$(".price").addClass('helper'); //for dyanmic addition to certain classes
$('body').append('<div class="price helper">19.00</div>'); //for adding afterward
发布于 2012-07-02 11:03:45
这对我起了作用:
与jQuery:
$('<style id="priceVisibility">div.results .price {display: none; }</style>').appendTo('head');
没有 jQuery:
// Appending style element to the head with a overriding style.
var style = document.createElement('style');
style.type = 'text/css';
style.id = 'priceVisibility';
style.innerHTML = 'div.results .price {display: none; }';
document.getElementsByTagName('head')[0].appendChild(style);
https://stackoverflow.com/questions/11299120
复制相似问题