vishalaksh
vishalaksh

Reputation: 2164

How to get width of the div inside the directive?

I have made a div and I want to get its width in its directive. How can I do it?

Here is the div:

<div scatter-chart id="divVisScatter-{{item}}" class="divVis divVisScatter col-sm-6">
    </div>

And the corresponding directive:

myApp.directive('scatterChart', function($window){
    return{
        restrict:'EA',
        template:"<svg width='850' height='200'></svg>",
        link: function(scope, elem, attrs){

            var d3 = $window.d3;
            var rawSvg=elem.find('svg');
            var svg = d3.select(rawSvg[0]); 

            //want to get the width of div here
                }
            };
        });

Upvotes: 1

Views: 142

Answers (1)

shaunhusain
shaunhusain

Reputation: 19748

You can use elem[0].offsetWidth to get the size of the div.

Upvotes: 4

Related Questions