Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

$(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?

1 Accepted Solution

Avatar

Correct answer by
Level 4

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.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 4

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.

Avatar

Level 5

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
});