Wednesday, February 9, 2011

.html() jQuery method bizzare bug -   resolves to empty space locally, but not on production.

I'm making a simple jquery command:

element.html("                 ");

using the attributes/html method: http://docs.jquery.com/Attributes/html

It works on my local app engine server, but it doesn't work once i push to the google server. The element empties, but doesn't fill with spaces.

So instead of " " (6 spaces) it's just "".

Once again, this is running on App Engine, but I don't think that should matter...

  • Have you tried using   instead of spaces? The html() method just pumps the string into the innerHTML of the element(s).

    From Sugendran
  • Your jQuery should look like this:

    $('element').html('  ');
    

    ... where ' ' equals once space.

    (with however many spaces you want, of course)

  • Is there a possibility that the code is minified as part of the process of being deployed onto the App Engine?

    I would not expect any string of whitespace to be retained as written, perhaps you could actually escape the white space and force any minification to leave it:

    example:

    element.html('\ \ \ \ \ \ \ \ \ \ \ \ ');
    From J5
  • This might not be a direct answer to your problem, but why are you even wanting to put in a heap of spaces? You can probably achieve the same result by just changing the padding-left or text-indent of that element.

    element.css("textIndent", "3em");
    

    Using a heap of  s is a very dodgy way to do indentation.

    From nickf
  • You could try generating the space during run-time, so it won't be trimmed or whatever happens during transport:

    element.html(String.fromCharCode(32));
    
    From davil

0 comments:

Post a Comment