Select all class's with getElementsByClassName and click does not fire in dtm | Community
Skip to main content
Level 3
September 3, 2016
Solved

Select all class's with getElementsByClassName and click does not fire in dtm

  • September 3, 2016
  • 12 replies
  • 11003 views

Hi,

I have a carousel with 6 links on the homepage and am trying to capture each link click. I have set up a data element using css selector to capture the classname i.e. [class=navname]

I also created an event based rule with condition rule set to _satellite.setVar('Navigation' this.text) and added  an evar,prop and events . Issue is that this only works on the first click, and not the others. I need this to click on all the other links.

I tried changing the rule to document.getElementsByClassName{'navname').click(); return true and it still only captures the 1st click and when i clicked on the others i get the link name for the first item returned for all the links.

How do i get this to click on all of the classes named 'navname' and return the correct navigation title? I thought maybe i need to declare a variable or something in the code editor.

please I need help as am just getting familiar with DTM

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ParitMittal

Hi Kee, 

Please use the following code . We have tested it our end and it is working . 

var a= this.getElementsByTagName("span")[0].innerHTML).split("</span>");; var b= this.getElementsByTagName("span")[1].innerHTML; _satellite.setVar("Navigation",a[1].replace(/(\r\n|\n|\r)/gm,"") + "-" +b ); // This statement creates a Data Element  "Navigation" and stores the Name of the link in it console.log(a); console.log(b); return true;

Thanks & Regards

Parit Mittal

12 replies

ParitMittal
ParitMittalAccepted solution
Level 10
September 8, 2016

Hi Kee, 

Please use the following code . We have tested it our end and it is working . 

var a= this.getElementsByTagName("span")[0].innerHTML).split("</span>");; var b= this.getElementsByTagName("span")[1].innerHTML; _satellite.setVar("Navigation",a[1].replace(/(\r\n|\n|\r)/gm,"") + "-" +b ); // This statement creates a Data Element  "Navigation" and stores the Name of the link in it console.log(a); console.log(b); return true;

Thanks & Regards

Parit Mittal

KeeMacAuthor
Level 3
September 12, 2016

Thanks Parit