admin管理员组文章数量:1432566
I have a custom meta box as part of my post editor. When the user changes the post title, I want to reflect this change in the content inside the meta box. I have seen plugins like Yoast do this but im not sure how.
I have tried using a jQuery event to do this but even if i wait for document.ready, it doesnt bind itself to the element.
jQuery(".editor-post-title__input").keyup(function(){
console.log(jQuery(".editor-post-title__input").val());
});
I have a custom meta box as part of my post editor. When the user changes the post title, I want to reflect this change in the content inside the meta box. I have seen plugins like Yoast do this but im not sure how.
I have tried using a jQuery event to do this but even if i wait for document.ready, it doesnt bind itself to the element.
jQuery(".editor-post-title__input").keyup(function(){
console.log(jQuery(".editor-post-title__input").val());
});
Share
Improve this question
edited Apr 16, 2019 at 17:59
Alexander Holsgrove
1,9091 gold badge15 silver badges25 bronze badges
asked Apr 16, 2019 at 10:22
user1889580user1889580
4621 gold badge5 silver badges18 bronze badges
1 Answer
Reset to default 1The event listener you have added will only attach to the available .editor-post-title__input
elements, and won't attach to any dynamically added elements. You are better to move the listener to the body as follows:
jQuery('body').on('keyup', '.editor-post-title__input', function(event){
console.log(jQuery(this).val());
});
Given the admin area is moving to use more React components, it's a good habit to get into.
本文标签: pluginsAccess post title from custom meta box on title change
版权声明:本文标题:plugins - Access post title from custom meta box on title change 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745582513a2664704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论