permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes createTextNode with html formatting? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "createTextNode with html formatting?" Watch "createTextNode with html formatting?" New topic
Author

createTextNode with html formatting?

Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
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

[SCJP 6]
[SCBCD in process]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

P.S. To create an element to which you can apply style without "breaking" use <span>, not <div>.
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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).



GenRocket - Experts at Building Test Data
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: createTextNode with html formatting?
 
Similar Threads
problem when integrating jspell with tinyMCE editor
checked radio button from an Enum value
JQuery Selector Help needed
A question of Sums
problem in Dynamic webform creation ?