Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript Help make a clickable DIV block

wyclef

Active Coder
Hi, I have this theme where an image, and some text are two separate blocks that share the same link so they currently operate separately and I wanted to get it where I could just click the main block and have it act as one link. I was trying out the following type of solution but it doesn’t seem to work wondering if anyone has any ideas how I could sort this out? The theme spits out a lot of code but I was trying to target the class that encompasses the two links, and then find the href link inside and assign a .click to the master div if that makes sense?

Code:
// page init
jQuery(function(){
    initBlockLink();
});

// block link
function initBlockLink() {
    jQuery('.single-wrapper').click(function(){
        window.location=$(this).find('a').attr('href');
        return false;
    });
}



<div class="wpb_column pos-middle pos-center align_center column_child col-lg-6 col-md-33 single-internal-gutter">
    <div class="uncol style-light">
        <div class="uncoltable">
            <div class="uncell no-block-padding">
                <div class="uncont" style="max-width:70%;">
                    <div class="uncode-single-media  text-left animate_when_almost_visible bottom-t-top" data-speed="1000">
                        <div class="single-wrapper" style="max-width: 100%;">
                            <div class="uncode-single-media-wrapper single-advanced">
                                <div class="tmb tmb-light tmb-text-showed tmb-overlay-text-anim tmb-content-left tmb-image-anim  tmb-img-ratio tmb-content-under tmb-media-first tmb-no-bg has-no-control">
                                    <div class="t-inside">
                                        <div class="t-entry-visual">
                                            <div class="t-entry-visual-tc">
                                                <div class="t-entry-visual-cont">
                                                    <div class="dummy" style="padding-top: 80%;"></div><a tabindex="-1" href="http://www.google.com" class="pushed">
                                                        <div class="t-entry-visual-overlay">
                                                            <div class="t-entry-visual-overlay-in style-dark-bg" style="opacity: 0.01;"></div>
                                                        </div>
                                                        <div class="fluid-object h2 font-699849 font-weight-500 is-no-control no-control-mobile-autoplay hasnt-poster object-size self-video" style="padding-top: 80%">
                                                            <div style="width: 640px;" class="wp-video"><video data-keepplaying class="wp-video-shortcode" id="video-131082-2" width="640" height="360" loop="1" autoplay="1" preload="metadata" muted="muted" playsinline>
                                                                    <source type="video/mp4" src="https://domain.com/wp-content/uploads/2023/10/video.mp4" /></video></div>
                                                        </div>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="t-entry-text">
                                            <div class="t-entry-text-tc single-block-padding">
                                                <div class="t-entry">
                                                    <h3 class="t-entry-title h2 font-699849 font-weight-500"><a href="http://www.google.com">Screen Recording 2023-10-10 at 11.00.10 AM</a></h3>
                                                    <p class="t-entry-excerpt ">Description Custom Text</p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
 
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
    
    </style>
   <script>
  
   </script>
  </head>
  <body>   
      <div class="wpb_column pos-middle pos-center align_center column_child col-lg-6 col-md-33 single-internal-gutter">
    <div class="uncol style-light">
        <div class="uncoltable">
            <div class="uncell no-block-padding">
                <div class="uncont" style="max-width:70%;">
                    <div class="uncode-single-media  text-left animate_when_almost_visible bottom-t-top" data-speed="1000">
                        <div class="single-wrapper" style="max-width: 100%;border: 1px solid #000">
                            <div class="uncode-single-media-wrapper single-advanced">
                                <div class="tmb tmb-light tmb-text-showed tmb-overlay-text-anim tmb-content-left tmb-image-anim  tmb-img-ratio tmb-content-under tmb-media-first tmb-no-bg has-no-control">
                                    <div class="t-inside">
                                        <div class="t-entry-visual">
                                            <div class="t-entry-visual-tc">
                                                <div class="t-entry-visual-cont">
                                                    <div class="dummy" style="padding-top: 80%;"></div><a tabindex="-1" href="http://www.google.com" class="pushed">
                                                        <div class="t-entry-visual-overlay">
                                                            <div class="t-entry-visual-overlay-in style-dark-bg" style="opacity: 0.01;"></div>
                                                        </div>
                                                        <div class="fluid-object h2 font-699849 font-weight-500 is-no-control no-control-mobile-autoplay hasnt-poster object-size self-video" style="padding-top: 80%">
                                                            <div style="width: 640px" class="wp-video"><!--video data-keepplaying class="wp-video-shortcode" id="video-131082-2" width="640" height="360" loop="1" autoplay="1" preload="metadata" muted="muted" playsinline>
                                                                    <source type="video/mp4" src="https://domain.com/wp-content/uploads/2023/10/video.mp4" /></video--></div>
                                                        </div>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="t-entry-text">
                                            <div class="t-entry-text-tc single-block-padding">
                                                <div class="t-entry">
                                                    <h3 class="t-entry-title h2 font-699849 font-weight-500"><a href="http://www.google.com">Screen Recording 2023-10-10 at 11.00.10 AM</a></h3>
                                                    <p class="t-entry-excerpt ">Description Custom Text</p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
document.querySelector('.single-wrapper').addEventListener('click', function(){this.querySelector('a').click()});
</script>
  </body>
</html>
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom