If that certain div is not so sensitive you don’t mind it being in the page HTML on initial load, then do so with all possible variants. By default they would all have the CSS property display: none;
Then have JavaScript or jQuery script execute on an element’s event such as onchange or onclick. The script will change the appropriate CSS property to display: block;
or display: inline;
. In the case of a dropdown, to account for the user making another selection, set all other possible variants to display: none;
just in case one of them is already on display from a previous event.
If there is only one dropdown on a page, JavaScript is simple enough, you don’t need jQuery unless you prefer to work with it. If there’s several on a page, as for a product grid perhaps, jQuery will greatly simplify the required code.
If the information is sensitive, you initially load an empty container. Then the on event script, instead of changing CSS, makes an AJAX request to the server for the content, then places the response in that empty container. Additionally, you would need server side PHP to handle the request.
I know you were hoping for code, but I’ve outlined the general approach. If you focus on just one step at a time, you should be able to find code examples of that step. Piece together the steps and you’ll have it. If you need to use AJAX, be sure to use code specifically for WordPress – it’s a bit different than the usual AJAX.