Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel1836's avatar

How do I run jQuery code when a Div becomes visible?

My code:

$('#display_section3').on('show', function () {
    $('#date').datetimepicker({ format: 'YYYY-MM-DD' });
    $('#time').datetimepicker({ format: 'HH:mm' });

});

Basically what happens is I click a button and the innerHTML of a div block with an ID (#display_section3) gets filled (with a form). It is not shown before that button click.

I'm trying to get the date picker plugin to work on that form. It doesn't work now. I managed to get it to work on.show of a modal ID but this is different.

How do I tell the code (and jQuery to run) to work when that Div appears?

Thanks

0 likes
2 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

Why don't you run the code, and just show it on the button click?

Please or to participate in this conversation.