2017-01-19 1 views
2

마지막으로 "rect"에 액세스하려고하므로 너비와 높이를 가져올 수 있습니다. 나는 JQuery와 $(".highcharts-plot-background").width() 다음 시도하지만 난 대답에 들어갈 모두 0이 또한 $(".highcharts-plot-background")[0].width()을 사용하려고하지만 그때 내가 제안을 열어주는 말들 다음과 같은 오류<rectangle><svg의 너비를 가져올 수 없습니다.

Uncaught TypeError: $(...).width() is not a function.

를 얻을.

<svg version="1.1" class="highcharts-root" xmlns="http://www.w3.org/2000/svg" width="710" viewBox="0 0 710 325" height="325"> 
 
    <desc>Created with Highcharts 5.0.0</desc> 
 
    <defs> 
 
    <clipPath id="highcharts-1"> 
 
     <rect x="0" y="0" width="636" height="238" fill="none"></rect> </clipPath> 
 
    </defs> 
 
    <rect fill="#ffffff" class="highcharts-background" x="0" y="0" width="710" height="325" rx="0" ry="0"></rect> 
 
    <rect fill="none" class="highcharts-plot-background" x="64" y="50" width="636" height="238" style="margin:0px;"></rect> 
 
</svg>

답변

1

사용 attr("width") 대신 width(). 만약 당신이 CSS에서 너비를 선언했다면 width() 잘 작동합니다.

아래 스 니펫을 참조하십시오.

console.log($(".highcharts-plot-background").attr("width"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<svg version="1.1" class="highcharts-root" xmlns="http://www.w3.org/2000/svg" width="710" viewBox="0 0 710 325" height="325"> 
 
    <desc>Created with Highcharts 5.0.0</desc> 
 
    <defs> 
 
    <clipPath id="highcharts-1"> 
 
     <rect x="0" y="0" width="636" height="238" fill="none"></rect> </clipPath> 
 
    </defs> 
 
    <rect fill="#ffffff" class="highcharts-background" x="0" y="0" width="710" height="325" rx="0" ry="0"></rect> 
 
    <rect fill="none" class="highcharts-plot-background" x="64" y="50" width="636" height="238" style="margin:0px;"></rect> 
 
</svg>

+0

고마워요. jQuery가 이러한 일을 처리한다고 생각했습니다. –

관련 문제