-1

Having code like this. need to prevent the div onclick when click on anchor tag.

<div onclick="window.open(url)">
  <p>
   .
   .
   .
  </p>
  <a href="link"/>

</div>

Not Duplicate question,here div tag has window.open(url), not js onclick function.

mano
  • 374
  • 1
  • 4
  • 11

1 Answers1

1

You have to first prevent default click functionality and then do like shown below

<div onclick="window.open(url)" class="parent_div">
  <p>
   .
   .
   .
  </p>
  <a href="link"/>

</div>



$(document).on('click', '.parent_div a', function(e) {

    e.preventDefault();
    let url = $(this).attr('href');
    window.location.assign(url)
});
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40