jQuery does not work on WordPress editor
I've added some content to WP's editor, however the new content does not
respond to the click behaviour. Here's how I've added the content:
add_filter( 'default_content', 'custom_editor_content' );
Then created my function custom_editor_content:
function custom_editor_content( $content )
{
$content = '
<button id="test">Add</button>
...';
echo $content;
}
The content is displayed within the editor ok, but it doesn't respond to
the jQuery that's being loaded like:
add_action( 'admin_menu', array( $this, 'fnEnqueueAdminScripts' ) );
The js loads ok, so does the content, but I cannot understand why the
click function doesn't work. Here's my js:
$( "#test" ).click(function() {
alert( "Test" );
});
Other snippets of js in the same file does work. The problem seems to be
with the click function. The content is not generated dynamically so I
don't think is a question of using on such as
$("#test").on("click", function() {
alert("test");
});
Any ideas of what I've done wrong?
No comments:
Post a Comment