Search code examples
phpjquerycsshyperlinkhref

Click div and go to page which another div contains


I have these two divs. I want to do: If I click "right_absolute" or "right_relative" div, then it goes to the page from link within "marka_w_miniaturce" div.

<div class="right_relative">
    <div class="right_absolute"></div>
</div>  

<div class="marka_w_miniaturce">
    <a href="<?php echo get_root().'galeria.php?g='.urlencode($id_gal); ?>" title="<?php echo htmlspecialchars($marka, ENT_QUOTES); ?>">
     <?php echo htmlspecialchars($marka, ENT_QUOTES); ?>
    </a>
</div>

Solution

  • $(document).on('click', '.right_relative', function() {
      var targetLocation = $('.marka_w_miniaturce a').first().attr('href');
      window.location.href = targetLocation;
    });