2013-10-22 64 views
1

的:寬度鑑於這種SVG多邊形SVG多邊形標籤

<polygon class="range_arrow" 
    id="arrow" 
    points="0,0 5,5 0,10 -5,5" 
    data-width="10"/> 

我可以,如果我手動輸入它的寬度。

$('#arrow').data("width"); 

然而$('#arrow').width();回報0$('#arrow').attr("width");回報undefined

是否有可能得到一個多邊形標籤正確的寬度?

+1

我不能看到一個錯誤......芽你應該使用.prop()而不是.attr() – Cracker0dks

回答

4

你可以得到邊界框,這會給你的寬度,例如

$('#arrow')[0].getBBox().width;