Equivalent of jQuery's contents().find() chained methods in pure JS

333 Views Asked by At

So I've been trying to do the following bit of code without jQuery:

$(".parent-class").contents().find(".child-class").css("color", "red");

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.

1

There are 1 best solutions below

2
On

You can try the following way:

document.querySelectorAll(".twitter-timeline .timeline-Tweet-text").forEach(function(el){
    el.style.marginBottom = "-10px";
 });