Skip to content
Advertisement

WordPress JavaScript

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 ?).

Screenshot

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.

$( "button" ).click(function() {
  $( "p" ).toggle();
});
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<button>Toggle</button>
<p style="display:none;">Good Bye</p>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement