The code I am trying is-

var newComponents = [];
newComponents.push(["aura:html", {
                                    "tag": "a",
                                    "body": "click",
                                    "HTMLAttributes": {
                                        "href": '#id=123',
                                        "onclick": "alert(\"test\")"

When I add the components using $A.createComponents method, it only renders the href attribute, but not onclick or press as well. I tried with class, id attributes also, they are getting rendered successfully. Any workaround?


Your onclick needs to be a reference to a controller method.

Try something like:

"onclick" : component.getReference("c.yourHandleClickMethod");

The reason that the onclick handler is removed is because it's treated like any other markup that you add - any directly executed javascript is removed at compile time.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.