Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

createTextNode with html formatting?

 
Karl Krasnowsky
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be some way to do this.

I simply want to take two strings, a label and it's value, via a JSON call and concatenate them (functionally) such as this:



If I attempt to do this:


the process will escape the control characters and I literally get the bold control characters in the resulting output.

Okay that's a pretty ugly solution anyway, so I tried using <div> tags and adding a class attribute that would apply the bold style through the css, so I wind up with this:


which works fine for applying the style, but it breaks the paragraph at the </div> tag and I would prefer it on one line. I guess I could go through the pain of generating a two column table to do this, but there must be some simple solution for this as a paragraph text node?

thanks,
Karl
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Text nodes are text nodes. If you want something else, you need to do something else. You can create the elements and their child text nodes, or go the innerHTML route.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. To create an element to which you can apply style without "breaking" use <span>, not <div>.
 
Karl Krasnowsky
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:P.S. To create an element to which you can apply style without "breaking" use <span>, not <div>.


Bingo! That's the answer. Thanks Bear.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could actually just use the label tag and apply a class to it. I find myself doing this...



...and then overriding when I need to. This allows me to type less code (no need to type class="label" for every span use).

 
Karl Krasnowsky
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:Or you could actually just use the label tag and apply a class to it. I find myself doing this...


Now that really is simpler. I guess it depends on whether you would want to use this style in other contexts. In this case probably not.

Thanks Gregg.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic