pravin
pravin

Reputation: 2155

Leading space is not getting retained in IE

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

Upvotes: 2

Views: 112

Answers (2)

Michel
Michel

Reputation: 9440

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

Upvotes: 1

Liam Spencer
Liam Spencer

Reputation: 936

You put

&nbsp;

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

Upvotes: 0

Related Questions