Dynamicly generated element as ContexMenu Target

Hi
I want to use dynamicly generated element with jquery as ContextMenuTarget. When I use ejMenu function in ( document ).readyit does not work  because element is not created yet which is fine.But when I use ejMenu inside element generate function, only the first created element is working(i mean contextmenu working).
As a result; My question is how to set dynamic generated element as context menu target.
Best Regards
İrfan


3 Replies

PO Prince Oliver Syncfusion Team January 31, 2018 06:02 AM UTC

Hi Irfannturk, 

Thank you for contacting Syncfusion forums. 

To set dynamic generated element as context menu target, you can specify a common class for the dynamic elements with context menu and set that class in contextMenuTarget property. Once the dynamic element is added to the DOM, you need to wire the context menu events to the element to display the context menu on that target element. Kindly refer to the following code.   

<button id="cxt" onclick="btnclick()" >Add dynamic target</button> 
 
<script> 
function btnclick(){ 
    var menuObj = $("#contextMenu").data("ejMenu"); 
    $("#sample").append("<div class='textarea context'> This is Dynamic content </div>"); 
    menuObj._contextMenuEvents("_on"); 
} 
</script> 

We have prepared a simple sample for your reference, please find the sample from the following link: https://jsplayground.syncfusion.com/2bdltwkn 

Regards, 
Prince 



IR irfannturk January 31, 2018 11:29 AM UTC

Hi Prince 

Thanks for your quick reply.Its work fine now.

Best Regards 

İrfan.



PO Prince Oliver Syncfusion Team February 1, 2018 04:40 AM UTC

Hi Irfannturk, 

Most Welcome. We glad that your issue is resolved.  

Regards, 
Prince 


Loader.
Up arrow icon