Applying attribute to SVG using JS prompts 'this.textBox.style is undefined'. Why?
I'm using the following code to draw an SVG text box, and then cha开发者_如何学Gonge its text anchor attribute to 'left' as it defaults to center and that's nasty.
The text generates correctly, but when I add this second line I get the error 'this.textBox.style is undefined' in my error console.
Here's my code:
RenderTextBox:function()
{
// Render Text
this.textBox = paper.text(this.x, this.y, this.htmlText);
this.textBox.style.textAnchor="left";
}
Any ideas?
I think what you want to do is
this.textBox.setAttribute('text-anchor', 'start');
(or, since it looks like you're using Raphael)
this.textBox.attr( 'text-anchor', 'start' );
The valid values for text-anchor
are start
, middle
, end
, and inherit
You can set it using bracket notation:
this.textBox.style['text-anchor'] = "left";
This way you don't actually have to make a function call.
精彩评论