首页 > 解决方案 > select and compare x or y from a svg rect in jquery

问题描述

How can i select and compare x or y element value from a svg rect in jquery?

svg looks like this:

<svg id="demo" width="100%" height="40" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <rect id="stretchy" x="20" y="40" width="100%" height="40" fill="#b7b7b7" stroke-width="5"></rect>
        <text x="50%" y="50%" font-family="Verdana" font-size="20" text-anchor="middle" dy=".3em"> text </text>
    </svg>

I wanna use it in something like this:

if($('#stretchy').css('x')!='20'){
code
}

标签: javascripthtmljquerycsssvg

解决方案


this is the answear to this question:

if($('rect[id="stretchy"]').attr('x')!='20'){ code }


推荐阅读