Rahul Desai
Rahul Desai

Reputation: 15501

Align text to support dynamic content

In my fiddle here, the % symbol is currently in fixed position. How do I align it so that it floats accordingly if the number changes from one digit to two digit to three digit?

I tried:

   .style("float", "left")

But it didnt work. What am I missing?

Upvotes: 0

Views: 64

Answers (2)

Unknown User
Unknown User

Reputation: 3668

You can simply concatenate with the % symbol and so it dances accordingly.

Demo

Upvotes: 2

maximkou
maximkou

Reputation: 5332

Not good, but worked Fiddle:

g.append("text")
 .attr(
     "x", 
     parseInt(textElement.attr("x")) + parseInt(textElement[0][0].clientWidth)
 ) 

Unknown User's solution correctly.

Upvotes: 3

Related Questions