I need to access the jQuery Object that is saved as an editor parameter and I don't know how to do it. Can someone explain to me what I'm doing wrong?
(function ($) {
var test = {
config: {
editor: $( "#wp-content-wrap" )
},
init: function(){
test.add_button();
test.enable();
test.load_events();
},
enable: function(){ },
disable: function(){ },
load_events: function(){ },
add_button: function(){
test.config.editor.before(
'<div class="builder-tools">' +
'<a id="switch-button" ' +
'href="javascript:void(0);">' +
'Activar' +
'</a>' +
'</div>')
}
};
$(document).ready(function () {
test.init();
});
})(jQuery);
What happens here is that the statement
$("#wp-content-wrap")
is executed when the.js
. This can happen BEFORE the page is finished loading, so it doesn't find it and has an invalid value when you calladd_buttons
.To solve it you can move the initialization of that variable inside the method
init()
since this method is called on document ready the element should be loaded in the DOM.Something like this, as you can see the button is inserted between the title and the wrapper: