admin管理员组文章数量:1415119
I'm using the following code to add the required attribute to a textarea tag.
HTML:
<label class="setting" data-setting="caption">
<span class="name">Beschriftung</span>
<textarea></textarea>
</label>
JavaScript:
jQuery(function(){
jQuery("label[data-setting='caption']").find("textarea").prop('required',true);
});
/
When I add an image to a text field in a post wordpress opens the media modal.
When I inspect the media modal with right click -> Inspect I can navigate to the following HTML element.
<label class="setting" data-setting="caption">
<span class="name">Beschriftung</span>
<textarea></textarea>
</label>
How can I make my JavaScript code run the jQuery function on the media modal?
I'm using the following code to add the required attribute to a textarea tag.
HTML:
<label class="setting" data-setting="caption">
<span class="name">Beschriftung</span>
<textarea></textarea>
</label>
JavaScript:
jQuery(function(){
jQuery("label[data-setting='caption']").find("textarea").prop('required',true);
});
https://jsfiddle/qp30Ljvo/
When I add an image to a text field in a post wordpress opens the media modal.
When I inspect the media modal with right click -> Inspect I can navigate to the following HTML element.
<label class="setting" data-setting="caption">
<span class="name">Beschriftung</span>
<textarea></textarea>
</label>
How can I make my JavaScript code run the jQuery function on the media modal?
Share Improve this question edited Aug 28, 2019 at 15:58 Osvald Laurits asked Aug 28, 2019 at 11:17 Osvald LauritsOsvald Laurits 1337 bronze badges 2- 1 Can you explain what you're trying to do? Should you be setting the caption somewhere in a Gutenberg object model rather than directly on the page? – Rup Commented Aug 28, 2019 at 11:38
- I'm trying to change the element <textarea></textarea> to <textarea required></textarea>. I know the jQuery syntax. I don't know how to access the page which contains the html element. – Osvald Laurits Commented Aug 28, 2019 at 11:42
1 Answer
Reset to default 0(function($){
//since only one label with data-setting='caption' exists, use this selector
$("[data-setting=caption]").children('textarea').attr('required', true);
})(jQuery);
I'm more curious as to how adding this would affect anything since these labels are not inside a <form>
element?
本文标签: imagesAccess html element in media modal with jQuery
版权声明:本文标题:images - Access html element in media modal with jQuery 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745203112a2647493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论