views:

33

answers:

2

Hi,

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

+1  A: 

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
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
You want to put encoded content in the DIV and later you want Javascript(jQuery) to read this information by useing the html()?
michel
I am sorry, i think I have not mentioned in detail, lemme give some more details of thisBelow is overview of processing on the input data :1) Get the contents from the DIV2) 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
mmmz ... you may want to look overhere:http://stackoverflow.com/questions/1495822/replacing-nbsp-from-javascript-dom-text-node
michel
@michel : Thanks....it helps me lot
pravin
A: 

You put

&nbsp;

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

Liam Spencer