Làm cách nào để tắt div trong HTML?

Dưới đây là 2 cách để vô hiệu hóa phần tử liên kết/liên kết HTML bằng cách sử dụng CSS hoặc bằng cách sử dụng JavaScript nội tuyến

Mục lục
  • Vô hiệu hóa neo HTML bằng CSS
    <style>
    .disabled-link {
      pointer-events: none;
    }
    style>
    <a href="https://google.com" class="disabled-link">Google.coma>
    
    0
  • Tắt neo HTML bằng JavaScript nội tuyến
    <style>
    .disabled-link {
      pointer-events: none;
    }
    style>
    <a href="https://google.com" class="disabled-link">Google.coma>
    
    1

Để tắt phần tử neo HTML bằng CSS, chúng ta có thể áp dụng kiểu

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
0

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
0 sẽ vô hiệu hóa tất cả các sự kiện nhấp chuột trên phần tử neo

Ví dụ

<a href="https://google.com" style="pointer-events: none">Google.coma>

Có thể đặt

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
1 bằng cách sử dụng các thuộc tính và bộ chọn CSS

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>

Đây là một lựa chọn tuyệt vời khi bạn chỉ có quyền truy cập vào các thuộc tính

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
2 hoặc
<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
3. Nó thậm chí có thể được sử dụng để vô hiệu hóa tất cả các liên kết HTML trên một trang

<style>
/* not recommended */
a {
  pointer-events: none;
}
style>
<a href="https://google.com">Google.coma>

Bây giờ chúng ta đã thấy cách vô hiệu hóa phần tử neo/liên kết HTML (thẻ

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
4) bằng cách sử dụng
<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
0, có thể được thực hiện mà không cần chạm vào thuộc tính
<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
6 hiện có bằng cách sử dụng các kiểu

Tiếp theo, chúng ta sẽ xem cách vô hiệu hóa phần tử neo/liên kết HTML bằng cách sử dụng JavaScript nội tuyến bên trong thuộc tính

<style>
.disabled-link {
  pointer-events: none;
}
style>
<a href="https://google.com" class="disabled-link">Google.coma>
6

Làm cách nào để ẩn div trong HTML?

display = “none” sẽ làm cho nó biến mất khi được nhấp vào div.

Làm cách nào để tắt div onclick trong JavaScript?

Bạn có thể vô hiệu hóa bất kỳ sự kiện nhấp chuột nào trên div hoặc nút bằng cách sử dụng JavaScript như minh họa bên dưới. .
1
Click Me
.
3