Skip to main content
AP_AW
Inspiring
August 7, 2016
Question

Use JavaScript to set onclick event

  • August 7, 2016
  • 1 reply
  • 7729 views

I'm trying to set an onclick event using JavaScript to a Cp smart shape called "item_01".

When I look at the HTML that is generated the shape does indeed have an onclick event attached but Cp "covers" it with at least two other shape-related elements making it impossible for "item_01" to get clicked by the user.

How can I use JavaScript to attach an onclick event to a smart shape that gets triggered by the user clicking the smart shape?

This topic has been closed for replies.

1 reply

TLCMediaDesign
Inspiring
August 8, 2016

Do you have the smartshape "use as button" option selected?

AP_AW
AP_AWAuthor
Inspiring
August 8, 2016

Yes, the smart shape is marked as 'use as button'.

TLCMediaDesign
Inspiring
August 9, 2016

So basically you have a smartshape, used as a button, and you don't have any objects covering it and you cannot click it?

I've found in a few instances, that other elements on the screen can cover other objects, like the div is actually much bigger than the object inside the div.

You can try putting the smartshape at the top of the timeline to see if the stacking order changes.

You can attach event listeners to any object with JS just as you would with a normal HTML page using:

document.getElementById("instancename").addEventListener("click", function(){

   doSomething;

});

But I imagine it still wouldn't be clickable since CP is covering it somehow. I use smartshapes all the time and I've only had issues when it is the last object in the slide array of elements or if I've cloned and object.

You could also use the interactiveItemSubmit listener. e.Data will have the name of the element you clicked.