Applying the attribute to SVG using JS hints "this.textBox.style - undefined". What for?

I use the following code to draw an SVG text box, and then change its text anchor attribute to "left", because by default it is centered and this is unpleasant.

The text is generated correctly, but when I add this second line, I get the error message "this.textBox.style is undefined" in my error console.

Here is my code:

    RenderTextBox:function()
{
    // Render Text
    this.textBox = paper.text(this.x, this.y, this.htmlText);
    this.textBox.style.textAnchor="left";
}

Any ideas?

+3
source share
2 answers

I think you want to do

this.textBox.setAttribute('text-anchor', 'start');

(or since it looks like you are using Raphael)

this.textBox.attr( 'text-anchor', 'start' );

Acceptable values for text-anchorare start, middle, endandinherit

+3

:

    this.textBox.style['text-anchor'] = "left";

, .

+1

Source: https://habr.com/ru/post/1749422/


All Articles