Hello, I’m building simply blog website with JS and I can’t display tags correctly. I’m beginner so I don’t understand much yet.
HTML
JS code
In the generateTags
function.
const ArticleTagsSelector = '.post-tags ul li';
There are no li
elements, they are the ones you are creating. The selector string should just be for the ul
const tagWraper = article.querySelectorAll(ArticleTagsSelector);
You just want querySelector
, not querySelectorAll
const linkHTML = '<li><a href="#' + tag + '"></a></li>';
You won’t see the links on the page unless you give them some text content.
tag.innerHTML += linkHTML;
tag
is an array element, not a DOM element. The line of code isn’t doing anything and isn’t needed.
As an aside. The function tagClickHandler
isn’t being used as a handler and you do not have access to event
or a click target inside it as it is being called as a plain function.
1 Like
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.