html - How can I make this JavaScript code display the post title? -
i using tumblr badge script embed tumblr feed on website. originally, there no post title support added code.
posttitle = document.createelement("h3"); posttitle.classname = "tumblr-post-title"; posttitle.innerhtml = post["regular-title"]; listitem.appendchild(posttitle); this display post title, on posts without titles displays "undefined" instead. there way fix this? thanks
if "regular-title" isn't property of post, return undefined. easy, quick fix return empty string if so:
posttitle.innerhtml = post["regular-title"] || ""; this check see if post["regular-title"] truthy value (not of these: false, 0, nan, undefined, "", null). if it's truthy, set innerhtml post["regular-title"]...otherwise "".
Comments
Post a Comment