Reputation: 93
so i have an array which gets multiple strings based on displayed charts. Now i am looking for the longest string within this array. Right now this works without problems.
The code for this looks like:
var textLengthArray = [];
domContainer.find(" g > .element1 > .element2> text").each(function () {
textLengthArray.push($(this).text());
});
var longestString = textLengthArray.sort(function (a, b) {
return b.length - a.length;
})[0];
Now i want to change the font size of those "text" elements based on the longest string. So if the longest string within the array is longer than 10 characters, the font-size should be changed to "x px/pt".
My first thoughts are all about something like:
if (longestString >= 10){
domContainer.find(" g > .brm-y-direction > .tick > text")
.style('font-size', '4pt')
};
i also have tried something like:
if (longestString >= 2){
$("g.brm-y-direction.tick").find("text").css("font-size", "4pt") ; };
But those solutions didnot work at all. So can anyone tell me how to solve this via javascript?
The generated HTML text looks like:
<g class="tick" transform="translate(0,74)" style="opacity: 1;">
<line x2="-6" y2="0"></line>
<text dy=".32em" x="-12" y="37" style="text-anchor: end;">sampletext</text></g>
Upvotes: 0
Views: 699
Reputation: 1395
I don't see brm-y-direction
in your HTML snippet, so you could try
$("g.tick text").css("font-size", "4pt");
Upvotes: 1