How to prevent the link from opening when you click on the button?

  • 0
    <style>
    	.a {
    		display: block;
    		width: 200px;
    		height: 200px;
    		background-color: #fff;
    		position: relative;
    	}
      .b {
    		display: block;
        width: 50px;
    		height: 50px;
        background-color: rgb(136, 170, 199);
        position: absolute;
        top: 5px;
        right: 5px;
      }
    </style>
    
    <a href="http://yandex.ru" class="a">
    	<button class="b">Es</button>
    </a>


    Question in title) The button cannot be removed from the link
    JavaScript Naomi Snyder, Jan 17, 2019

  • 4 Answers
  • 0
    There is no need to invent something. The button is inside the link, respectively, by pointing at the button in any way, we get to the link. Better not to suffer and take them outside each other.
    Anonymous

  • 0
    Alex, there is a card, when you click on it, its full version opens, and this card has a like. So when I like it, a full card opens and I like it, but I only need a like.



    In the handler for clicking the like button, you need to add a call stopPropagation
    Emily Beasley

  • 0
    href = "#" put a stub
    Emma Ramos

  • 0
    .b {
    pointer-events: none;
    }
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!