MoFish Posted July 15, 2016 Share Posted July 15, 2016 Hi, I have a WYSIWG editor (called summernote) on my page. I also have a button #add-another which will clone the editor and add multiple. The issue im having is that im unclear on how best to re-initialise the editors on a button click, as the page does not reload. Can anyone advise? Should i somehow destroy the editors, then reinitialise? little confused. I have the following so far, but not sure if im going down the right path, as its not working correctly. Regards, MoFish <script> $(document).ready(function() { function initialize() { $('.wysiwyg').summernote({ height:150, minHeight: null, maxHeight: null }); } initialize(); $("#add-another").click(function(e) { e.preventDefault(); $("#meta-clone").clone().appendTo("#meta-container"); initialize(); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/301486-jquery-re-initialize-query-on-click/ Share on other sites More sharing options...
kicken Posted July 15, 2016 Share Posted July 15, 2016 There is no need to re-initialize already existing editors, you only need to initialize the one in your new cloned area. You'd do that by finding the editor element in the clone then calling the summernote function on it. $("#add-another").click(function(e) { e.preventDefault(); var clone = $("#meta-clone").clone(); clone.appendTo("#meta-container"); clone.find('.wysiwyg').summernote({height: 150, minHeight: null, maxHeight: null}); }); On another note, if your currently cloning an existing already-initialized editor you should probably not be doing that. The clone should only have the editor placeholder element, then you initialize the editor after cloning. Quote Link to comment https://forums.phpfreaks.com/topic/301486-jquery-re-initialize-query-on-click/#findComment-1534541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.