Theme Developer Tutorial: 6. Using the JS API

I want to affect posts only in a particular category. I can’t figure out a way to tell if an element is in a given category. I thought I might use element.parentElement and work my way up to the body, but that doesn’t seem to work. Before I’ve solved this problem when I realized that I could tell if I wanted to change things if the user was in a particular group, so I could use currentUser, but right now, I’m doing this:

if (!cooked.innerHTML.includes(newFormText)) {
      console.log("fixSubmittedForm no new form text");
      return;
    }

Searching all of every post to decide if I want to change it seems bad, right? It’s a hosted customer or I’d have solved this problem a bunch of ways with a plugin.

1 Like