开发者

cannot call method appendChild of undefined

开发者 https://www.devze.com 2023-04-01 08:32 出处:网络
Iget this error when I insert a a href tag inside innerHtml in the javascript (flickrshow-7.1.js), for inserting a link for an image. Images are pulled from the flickr account using flickrshow javascr

I get this error when I insert a a href tag inside innerHtml in the javascript (flickrshow-7.1.js), for inserting a link for an image. Images are pulled from the flickr account using flickrshow javascript and displayed in the website as slideshow.

a.onLoadWindow = function() {
    a.elements.target = typeof a.elements.target === "string" ? document.getElementById(a.elements.target) : a.elements.target;
    a.elements.target.innerHTML = '<a href="http://www.google.com"><div class="flickrshow-container" style="background:transparent;height:' + a.elements.target.offsetHeight + "px;margin:0;overflow:hidden;开发者_Go百科padding:0;position:relative;width:" + a.elements.target.offsetWidth + 'px"></div></a>';


The undefined error means the javascript variable you are tying to call appendChild on doesn't have a value. You need to fix the initialization so it has a value on which to call appendChild

<p id="parent"></p>

...

var newNode = document.createElement("li");
var parent; 
parent.appendChild(newNode);  // Error!!! What is parent?
parent = document.getElementById("parent");
parent.appendChild(newNode);  


An img element has no innerHTML, and you can not append a child node to an img. Wrap the images in the a elements instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消