In the following program, I am adding a div to svg, by d3. It is appended properly as can be seen in the dom structure of chrome browser. But, I cannot see the background or its visibility in the webpage.
SNIPPET:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js"></script>
<style>
svg{border:2px solid black;}
.red{width:50px;height:50px;background:red;}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<svg></svg>
<script>
//module declaration
var app = angular.module('myApp',[]);
//Controller declaration
app.controller('myCtrl',function($scope){
$scope.svgWidth = 500;//svg Width
$scope.svgHeight = 300;//svg Height
//resetting svg height and width in current svg
d3.select("svg").attr("width", $scope.svgWidth).attr("height", $scope.svgHeight);
//Setting up of our svg with proper calculations
var svg = d3.select("svg");
//for x axis
svg.append("div").attr("class", "red");
});
</script>
</body>
</html>
RESULT:
DOM:
NOTE:
My div is appended already. Its case of visibility only. So its different from ---> is it possible to append a div inside svg element