等同于纯JS中jQuery的contents().find()链式方法 [英] Equivalent of jQuery's contents().find() chained methods in pure JS
本文介绍了等同于纯JS中jQuery的contents().find()链式方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我一直在尝试在不使用jQuery的情况下执行以下代码:
So I've been trying to do the following bit of code without jQuery:
$(".parent-class").contents().find(".child-class").css("color", "red");
我正在尝试编辑嵌入式Twitter feed 的样式,并且无论出于何种原因,我都只能通过使用以下代码段来获取模块的子节点:$(".twitter-timeline").find(".timeline-Tweet-text").css("margin-bottom", "-10px");
.纯粹的JS代码模仿此功能必要.
我完整的js函数是:
I'm trying to edit the styles of an embedded Twitter feed and I could only do that by getting the module's child nodes using this snippet: $(".twitter-timeline").find(".timeline-Tweet-text").css("margin-bottom", "-10px");
for whatever reason. It is necessary that the pure JS code mimics this functionality.
My full js function is:
// Change the style of the tweets after the module loads.
window.addEventListener('load', function () {
$(".twitter-timeline").contents().find(".timeline-Tweet-text").css("margin-bottom", "-10px");
});
感谢您抽出宝贵的时间阅读.
Thanks for taking the time to read.
推荐答案
您可以尝试以下方式:
document.querySelectorAll(".twitter-timeline .timeline-Tweet-text").forEach(function(el){
el.style.marginBottom = "-10px";
});
这篇关于等同于纯JS中jQuery的contents().find()链式方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文