0

I have a data in the object section_data.title and i am trying to use str.sup() where str=section_data.title; and str holds following data:

str="Not less than 30 net ft2 (2.8 net m2) per patient in a hospital or nursing home, or not less than 15 net ft2 (1.4 net m2) per resident in a limited care facility, shall be provided within the aggregated area of corridors, patient rooms, treatment rooms, lounge or dining areas, and other similar areas on each side of the horizontal exit. On stories not housing bed or litterborne patients, not less than 6 net ft2 (0.56 net m2) per occupant shall be provided on each side of the horizontal exit for the total number of occupants in adjoining compartments."

Now I want to add superscript for the bold words indicated above (e.g ft2). How can I do this using str.sup() or are there any other alternative method to do so in javascript? Or any other tricks?

1 Answer 1

1

String in javascript is not formatted. You can only do that when you output to HTML. So basically you must write it like this

var str = "Not less than 30 net ft<sup>2</sup> (2.8 net m<sup>2</sup>)";
document.write(str);

You can do a find and replace for all string contain ft2 and m2 turn them into ft<sup>2</sup> and m<sup>2</sup>

str.replace(/ft2/g,"ft<sup>2</sup>");  //But it not safe...
Sign up to request clarification or add additional context in comments.

2 Comments

Why you are saying that it's not safe? Can you explain?
Because you may accident replace some other string as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.