I’m trying to achieve a custom option inside the “Publish Metabox” in WordPress admin custom post. And I want to know is there any native way to do expand/collapse divs (Check the below screenshot).
I wonder how WordPress itself achieves it like the below screenshot? (Maybe match the IDs like bootstrap JS libraries do ?).
Advertisement
Answer
And I want to know is there any native way to do expand/collapse divs.
There is. WordPress uses the jQuery library on the admin side for interactive elements. In this case, it’s just using a simple toggle effect.
Display or hide the matched elements.
- Source @ https://api.jquery.com/toggle/
JavaScript
x
3
1
$( "button" ).click(function() {
2
$( "p" ).toggle();
3
});
JavaScript
1
3
1
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
2
<button>Toggle</button>
3
<p style="display:none;">Good Bye</p>