Skip to content

Instantly share code, notes, and snippets.

Last active September 14, 2017 12:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
* Function for adding Custom Variables for Usabilla In-Page widget based on the textContent from an Element based on a classname.
* Use this function after the function usblInPageAppendToClassMulti and before the loading of the in-page install script.
* @param {String} classnamedata [The classname of which the textcontent will retrieved]
* @param {String} propertyname [The property name that should be used for the custom variables]
function usblInPageAddCustomVarMulti(classnamedata, propertyname){
var inPageWidgetElementList = document.querySelectorAll("div[ub-in-page]");
var faqToggleElementList = document.getElementsByClassName(classnamedata);
var arrayLengthInpage = inPageWidgetElementList.length;
var arrayLengthFaqToggle = faqToggleElementList.length;
var customVarValue;
var inPageWidgetElementNode;
for (var i = 0; i < arrayLengthInpage; i++) {
inPageWidgetElementNode = inPageWidgetElementList[i];
customVarValue = faqToggleElementList[i].textContent.trim();
var usblInPageCustom = document.createAttribute("ub-in-page-" + propertyname);
usblInPageCustom.value = customVarValue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment