Access html element in media modal with jQuery

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.net/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?

Read more here:: Access html element in media modal with jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *