Problem to append new IMG element, wrapped in DIV, in Opera browser
I run into weird problem while testing my script on Opera browser.
One of the script tasks, to get thumbs images from youtube, and to put them into <DIV>
container.
So I do the following:
$ytbID = $ytbURL.match("(.+?)(\/v/)([a-zA-Z0-9_-]{11})+");
$ytbImg = "http://img.youtube.com/vi/"+$ytbID[3]+"/2.jpg";
//building container for youtube image
$(this).before('<div class="youtoobin" align="left"></div>');
$(this).prev(".youtoobin").append('开发者_开发知识库<div class="thumby" style="background-image:url(' + $ytbImg +'); width:120px;height:90px;cursor:pointer;"><img style="margin:31px 38px;" src="/myscripts/mini-play.png"/></div>');
Now the strange thing in Opera, that sometimes it works and sometimes it doesn't, I mean sometimes 'append()
' returns null
. It worked flawlessly in all other browsers I tested with (FF, Chrome, IE 6,7,8). I just can't get if there is a problem with append()
with Opera or with me?
Thanx for help.
Sam
Could be a "timing" issue (the div you append is not ready when you try to insert content into it), what does this give:
var $div = $('<div class="youtoobin" align="left"></div>');
$(this).before($div);
$div.append('<div class="thumby" style="background-image:url(' + $ytbImg +'); width:120px;height:90px;cursor:pointer;"><img style="margin:31px 38px;" src="/myscripts/mini-play.png"/></div>');
精彩评论