• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

createTextNode with html formatting?

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic