JPFotoz
JPFotoz

Reputation: 105

Error in Custom Google Tag Manager JavaScript

Trying to setup a custom JavaScript in GTM where the innerHTML value is checked for X and if it is X fires.

Here's what I have so far but it's not firing correctly

function() {
  var el = document.getElementById('ltrNumPlaceholder');
  if (el == null) return 0;
  return parseInt(el.innerHTML);
 }

I also tried this but GTM complains there there is a syntax error on a line that doesn't exist. (GTM error message for the below is: "Error at line 5, character 2: Parse error. ')' expected.")

function(){
   var stepNum = document.getElementById('ltrNumPlaceholder').innerHTML;
   if(stepNum == 2)return parseInt(stepNum);
};

Thanks for your help in advance.

Upvotes: 0

Views: 9582

Answers (1)

nyuen
nyuen

Reputation: 8907

To fix the error message, just remove your semicolon at the end of the function (after the closing curly bracket), and that should work.

Upvotes: 5

Related Questions