jQuery. Prepend with fadeIn (error)
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 err开发者_运维知识库or
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
Try this:
$(html).hide().prependTo('#test').fadeIn('slow');
You probably cannot use animation methods when the element is not added to the DOM.
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)
);
});
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/
精彩评论