0

I am developing a mobile website in JQuery Mobile and I am fining that at seemingly 'random' points, the web browser is adding in:

"        "

(different amounts on the different pages it occurs).

Much of the base of the code is copied and pasted straight from the JQM demo site for the different widgets/layouts etc... and I have read that copying/pasting code from different places can cause this issue. The problem is, how do I remove it, especially when I have already done a reasonable amount of coding?

I have tried copy/pasting it into notepad, saving as a plain text doc and then copy/pasting back into my editor (Sublime text 2) but that doesn't seem to work.

I'd prefer a procedural solution over having to add a line of script to strip it out at the browser end if possible.

An example of this can be seen on this page: http://noee.brandallareas.co.uk/#delegates , There is not meant to be that much space between the tables (you can see the added space characters through firebug/element inspector).

user3929908
  • 31
  • 1
  • 5
  • have you tried jquery trim()? http://api.jquery.com/jquery.trim/ – andrew Jan 23 '15 at 13:00
  • no, but would I have to add it to every section of code that has the space created or just once for the page? Like for the example page, would I therefore have to add it at the beginning of each table? – user3929908 Jan 23 '15 at 13:37
  • you need to add it to every string your script creates - trim() will remove white spaces from start and end of string. You can look here also for another way: http://stackoverflow.com/questions/7589528/is-it-possible-to-remove-nbsp-using-jquery – andrew Jan 23 '15 at 14:32
  • What makes you think the *browser* is adding them? Authoring tools may do such things; though I have only seen them change normal spaces to ` ` (which is annoying enough). But to get help with this, you need to identify *what* software does this. And it's probably off-topic at SO, unless it is about programs that you have created or are modifying. – Jukka K. Korpela Jan 23 '15 at 15:15
  • It could just as easily be Sublime Text 2 that is adding the spacing and probably more likely as the spacing is prevalent in all browsers, I meant that the code has been interpreted by the browsers in this way as it isn't visible in the editor. I have also tried closing up the gaps between tags on a sample part of the code and that doesn't remove them either which made me think they were added 'post editor'. – user3929908 Jan 23 '15 at 16:52
  • Also, with regards to using jquery trim(), I am quite new to jquery on the whole and after reading the api link you supplied andrew, I am unsure on how I would use it in this situation. It appears to be isolated to the tag in this instance and another that I am working on (http://noee.brandallareas.co.uk/15dev/#keydates), I can take all the data-role/class/surrounding divs away with the same result, yet if I comment out the
    tag, it goes away (and naturally breaks the layout). I guess therefore i need to somehow attach trim() to the tag as opposed to a string as such?
    – user3929908 Jan 26 '15 at 12:12

3 Answers3

3

I have found the answer, I asked the question on another forum and got this which has solved the issue. I thought I would post here for future reference:

If you copied from the formatted display in your web browser, rather than using "view source", you now have Unicode \0xA0 characters in your document. Use your text editor to search and remove them. Alternately, you can install a plugin that will highlight non-ASCII characters. (I think there is one called "Unicode Highlighter" - there may be others.)

(Posted by - watusiware)

The original forum thread is here.

user3929908
  • 31
  • 1
  • 5
1

This problem occurs when you copy and paste the source code from some website. In this way you copy invisible blank spaces which are further converted/rendered as   in the browser.

You need to manually remove the spaces between the tags and elements. Please do the indentation by yourself. It should work :)

0

I already faced this problem it usually happens when you use to copy and paste the source code from another project or file.. Remove the Unnecessary spaces... Unnecessary spaces