Adding attributes to an element through custom code Answered
Anyone knows how to add attributes to an element through custom code(I know it's possible)?
Use case would be: data-ms-content="!CMS_FIELD"
Basically need to have "!" in front of a field pulled from CMS,
Comments
2 comments
const element= document.querySelector("{Insert #id or .class");
element.setAttribute("data-ms-content", "!"+{CMS_FIELD});
I actually found this but forgot to send it here.
myElement.setAttribute('data-ms-content', '!CMS_LINK');
}); </script>
Please sign in to leave a comment.