2

I am working on one application, i am facing one problem on Internet Explorer while retrieving inner HTML of div.

I have below input for retrieving :

<div> This is first segment</div>

I have used jquery script to extract content. i.e.

$('div').html();

Output after using above statement :

This is first segment

Here not retrieving leading space present in div.
I am expecting here is :

 This is first segment

I am facing this problem on Internet Explorer, It's working properly on FireFox.

Please suggest your thoughts on this.

Thanks in advance

pravin
  • 2,155
  • 8
  • 37
  • 49

2 Answers2

1

I think there is nothing to do about this. Maybe you can do it the safe way:

<div>&nbsp;This is first segment&nbsp;</div>

or try jQuery text()

Or try the non jQuery functions innerHTML innerText

Michel
  • 9,220
  • 13
  • 44
  • 59
  • Thanks a lot michel for your quick response. I just want to add one more point here is that, i have used in later stage encoding/decoding of this data so there i'll need to take care of this encoding. Is there any other way apart from this solution.....may be with jquery or in javascript itself. – pravin Jul 27 '10 at 08:47
  • 1
    You want to put encoded content in the DIV and later you want Javascript(jQuery) to read this information by useing the html()? – Michel Jul 27 '10 at 08:50
  • I am sorry, i think I have not mentioned in detail, lemme give some more details of this Below is overview of processing on the input data : 1) Get the contents from the DIV 2) Apply Encoding to this..and process on that ( here some logic has been applied ) 3) Again I have decoded this data. ( Added some other logic ) This way i have applied encoding/decoding for the data. Here my point is if i use   as mentioned above. I need to spend more efforts to take care of this in encoding/decoding, so that i wont impact on other features in my application. – pravin Jul 27 '10 at 08:57
  • mmmz ... you may want to look overhere: http://stackoverflow.com/questions/1495822/replacing-nbsp-from-javascript-dom-text-node – Michel Jul 27 '10 at 09:01
0

You put

&nbsp;

before the text to force a non breakable space. This is recognised by all browsers.

Liam Spencer
  • 936
  • 1
  • 11
  • 25