Failed To Execute 'appendchild' On 'node': The New Child Element Is Null
Solution 1:
Several issues here:
document.body.appendChild(ogImg);
is just wrong.ogImg
is anodeList
. You can't directly append anodeList
to the body AND it's already in the DOM (you just got it withdocument.getElementsByClassName("og-fullimg");
.You are using
$(document).ready()
to wait to call .bxSlider(), but NOT using it to calldocument.getElementsByClassName()
. My guess would be your code is just running too soon. If that is the case, then just put all your code inside the.ready()
handler.You're using a very odd mix of plain javascript and jQuery when switching the plain javascript over to jQuery could make your code smaller and more consistent. If you have jQuery, you may as well use it for what it's good at (which is selectors and operations on collections - among other things).
This is what I'd suggest:
//create and initialize the slider.
$(document).ready(function() {
var bxSlider = $("<ul class='bxslider'></ul>"), img;
for (var i = 1; i < 4; i++) {
img = newImage();
img.src = "images/bid_" + i + ".jpg";
$("<li>").append(img).appendTo(bxSlider);
}
bxSlider.appendTo(".og-fullimg");
bxSlider.bxSlider({
auto: true,
pager: false,
adaptiveHeight: true,
slideWidth: 550
});
});
Post a Comment for "Failed To Execute 'appendchild' On 'node': The New Child Element Is Null"