How I can add conditional OnClick
Application Type

Hello all,

I'm trying to add a conditional OnClick in one element inside a List. I Tried with JavaScript and if the element is outside of List works if it's inside the List not works.

My JavaScript:

element = document.getElementsByClassName("to-add-click");

button = document.getElementById($parameters.ButtonId);

element.onclick = function() {; // this will trigger the click event


Someone have idea how I can put this working?

Thanks in advance, Paulo Torres


I think we can change a way to achieve this. Every element can trigger this event, and we can check whether this element is inside the list in the event, if not, then do the logic, else go to end.

It's not a solution because the elements will be clickable.

I have a workaround with if but it's not so beautiful and well done as I like.


Well, I see. So how can we know whether the element is in the list or not? You should have a flag to check this right? So can we add a 'if' in the list, then we check the flag, if element is inside the list, then shows a label, and if the element is outside the list, the shows a link or button which can trigger the event.

Hi Paulo,

can you tell a bit more about the context.  Is there a reason why you are trying to do this with Javascript ?

At first glance, I would say, why not solve it low code by putting an if around your element with the condition, in the true branch add a click event, in the false branch, no click event ??



Or alternatively, if you don't like duplicating the same element in an true and false branch (for maintenability reasons, for example) you can attach the onclick event to all items in your list, but have different style dependent on your condition, where you make the else CSS class pointer-events:none.

See attached oml for both options.


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