How to set the background-color of a D3.js svg?

I'm not very familiar in styling D3.js SVG's. I create a collapsible tree and will provide an option to download this tree as SVG/PDF/PNG. This works great but the background-color of the resulting files is always transparent. Is there a possibility to create the D3 SVG with a specific background-color? I used this example for my work:

Thank you!


Just add a <rect> as the first painting order item that displays the colour you want.

var svg ="body").append("svg")
    .attr("width", width + margin.right + margin.left)
    .attr("height", height + + margin.bottom);

    .attr("width", "100%")
    .attr("height", "100%")
    .attr("fill", "pink");

    .attr("transform", "translate(" + margin.left + "," + + ")");