Why does $(selector).onclick = function() work in the developer console but not in Adobe Launch? | Community
Skip to main content
Sathya_Murugaiyan
Level 2
October 7, 2022
Solved

Why does $(selector).onclick = function() work in the developer console but not in Adobe Launch?

  • October 7, 2022
  • 2 replies
  • 1640 views

$(document).on("click","button",function() {

......

});

this worked in Adobe launch for button tagging.



$("button").onclick = function() {
......
};

This function works in the developer console and not in Adobe Launch. Does anyone have any idea why this does not work in Adobe launch?

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 tim_funk

It looks like you may be relying on jquery (based on usage of ($). I'd check your source HTML and see if jQuery is being loaded BEFORE or AFTER Adobe launch is loaded on the page. If jQuery is loaded AFTER, you'd see the error from launch, but by the time you check the developer console - jQuery is loaded.

2 replies

tim_funk
tim_funkAccepted solution
Level 3
October 7, 2022

It looks like you may be relying on jquery (based on usage of ($). I'd check your source HTML and see if jQuery is being loaded BEFORE or AFTER Adobe launch is loaded on the page. If jQuery is loaded AFTER, you'd see the error from launch, but by the time you check the developer console - jQuery is loaded.

Sathya_Murugaiyan
Level 2
October 7, 2022

Thank you

ranjithd
Level 4
October 7, 2022

statement: $("button").onclick = function() {
......
};

Here statement is, not function decalring method, because onclick is older Javascipt method and $('button') is Jquery. So you are overrighting function declaring method. So Dom not excuding your script.

Instead of you can define the function on below full javascript method or full jquery method.


Here, Javascipt method.

<!DOCTYPE html>
<html>
<body>
<p id="button">Click me.</p>

<script>
document.getElementById("button").onclick = function() {myFunction()};

function myFunction() {
document.getElementById("button").innerHTML = "YOU CLICKED ME!";
}
</script>

</body>
</html>

Here, Jquery method. I hope you already working script with 2nd method.
Method 1 (old):
$('button').click(function(){
//do something
});

Medthod 2 (new):
$(document).on("click", "button", function(){
//do something
});