Q: Close popup window if i click to another div I have a popup window which is opened using this code:
Update:
<ul class="grid cs-style-1">
    <?php 
    $explainname = new wp_query( array ( 'post_type' => 'explainname' ) );  
    if ( $explainname->have_posts() ) : while ( $explainname->have_posts() ) : $explainname->the_post();
    $explainname_icon = get_post_meta( $post->ID,'explainname_icon', true );
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $imageContent = get_the_content();
    $stripped = strip_tags($imageContent, '<p> <a>'); //replace <p> and <a> with whatever tags you want to keep after the strip

    ?>          
            <li class="desktop">
                <figure>
                    <img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
                    <figcaption>
                        <h3><?php the_title(); ?></h3>
                        <span style="text-align:right;font-size: 15px;"><?php echo $stripped; ?></span>
                    </figcaption>
                </figure>
            </li>
            <li class="popup" onclick="myFunction<?php echo $post->ID; ?>()">
                <figure>
                    <img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
                    <span class="popuptext" id="myPopup<?php echo $post->ID; ?>"><?php echo $stripped; ?></span>
                </figure>
            </li>
            <script>
            // When the user clicks on <div>, open the popup
            function myFunction<?php echo $post->ID; ?>() {
            var popup<?php echo $post->ID; ?> = document.getElementById("myPopup<?php echo $post->ID; ?>");
            popup<?php echo $post->ID; ?>.classList.toggle("show");
            }

            </script>

    <?php 
    endwhile; endif;
    wp_reset_query();
    ?>                  
</ul>

How can I close that popup from within the popup?
I mean I need clase any open popup, When i click on new div

A: Use this example
<script>
    $(document).not("#myPopup<?php echo $post->ID; ?>").click(function() {
        $('#myPopup<?php echo $post->ID; ?>').hide();
    });
</script>


A: Here is a solution. When you click on a DIV, it will close your popup. If you want to target all popups then you need to give them all a common class name.
document.getElementsByTagName('div').onclick = function(e){
    document.getElementById("myPopup<?php echo $post->ID; ?>").style.display = 'none';

});


A: simply use this in javascript
var popup<?php echo $post->ID; ?> = document.getElementById("myPopup<?php echo $post->ID; ?>");
window.onclick = function() {
    if (popup.classList.contains("show")) {
        popup.classList.toggle("show");
    }
 }

