0

I've used code from here jquery prepend + fadeIn

Without fadeIn it works

function updateResult(data) {
$('#test').prepend(
    html
);
}

But with fadeIn works only when data contains one div tag,

$('#test').prepend(
    $(html).hide().fadeIn('slow')
);

otherwise FireFox returns error

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://code.jquery.com/jquery-latest.min.js :: <TOP_LEVEL> :: line 16" data: no]

How it possible rewrite this code?

Upd. In my situation I've solved it this way

data = data.replace(/(?:(?:\r\n|\r|\n)\s*)/gi, '');
$(data).hide().prependTo('#test').fadeIn('slow');

After removing line breaks works as should

Community
  • 1
  • 1
Tuco
  • 857
  • 2
  • 12
  • 26

3 Answers3

1

Try this:

$(html).hide().prependTo('#test').fadeIn('slow');

You probably cannot use animation methods when the element is not added to the DOM.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • @Tuco: Then it is something else, because it works in Firefox for me: http://jsfiddle.net/fkling/duM7a/ You could also try to change the order of the calls: `$(html).prependTo('#test').hide().fadeIn('slow');` though this might result in flickering. – Felix Kling Apr 25 '11 at 23:48
  • maybe it is something with CSS, because yours code does not use it, my does and in error there is nsIDOMViewCSS.getComputedStyle – Tuco Apr 25 '11 at 23:52
1

Testing this code in Firefox and Chrome. I haven't tested with AJAX:

HTML

<div id="be-images">
    <ul>
        <li>lista</li>
    </ul>
</div>
<button type="button">button</button>

JQUERY

$('button').click(function(){
$('#be-images ul').prepend(
    $('<p>response</p>').hide().fadeIn(2000)
);
});
msmafra
  • 1,704
  • 3
  • 21
  • 34
0

The problem seems to be in linebreaks.

After reading this thred Common sources of unterminated string literal I get a hind. The server return html code where tags located each on new line, so when \n and space between tags were removed this error disappeared.

Here an example http://jsfiddle.net/gMWFD/

Community
  • 1
  • 1
Tuco
  • 857
  • 2
  • 12
  • 26