Attach click event handler to dynamic HTML

Hi,

In mobile application screen, I am dynamically adding HTML in DOM. I want to attach client action as an event handler for on click of DIV.

Below code is not working. 


Below code is directly calling client action -

How should I attach on click event handler to DIV?

Best Regards,

Nitin

mvp_badge
MVP

Hi Nitin,

you can create Function in javascript and bind this function onclick event.

Inside this function call this action by button like -

document.getElementById('ButtonId').click();

and hide this button by css as display:none;


Hope this will help you.

Regards

Rahul


mvp_badge
MVP

Hi Nitin,

Below mentioend implementation is the other solution which I could suggest for the mentioned use-case.

See this sample implemenation DynamicHTML With Event

Refer to the attached .oml file


JavaScript Snippet:

window.showMsg = function () {
    $actions.ShowGreetings();
};

var paramTxt = "<div class='greetingCntr' onclick= showMsg();>Click Here!</div>";

document.getElementById($parameters.PlaceholderId).innerHTML = paramTxt;


Hope this helps you!


Kind regards,

Benjith Sam

MobileLabHTMLEvent.oml

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.