Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Wilson Edwards
at 2025-04-14 01:22:51
Point:500 Replies:2 POST_ID:829362USER_ID:12108
Topic:
javascript
For example,
I have a link in DIV-A tag now I can not click the link in DIV-A
because it is covered by DIV-B
I want to click the link DIV-A anyway.
I tried this example, it work at https://computer28.com/learn/pointer-events.php
Any other good example or other method to achieve this ?
Please advise
Expert: rcschroeder replied at 2025-04-14 01:24:49
You're trying to propagate a pointer event from one element (DIV-A) to another element (DIV-B) that is covering it. This can be achieved using CSS and JavaScript. Here are a few methods you can try:
**Method 1: Using pointer-events**
You've already seen this method in the example you provided: https://computer28.com/learn/pointer-events.php
Add the following styles to your DIV-A element:
```css
div div {
pointer-events: none;
}
```
And then add `pointer-events: auto` to the DIV-B element that is covering DIV-A. This will allow pointer events to propagate from DIV-A to DIV-B.
**Method 2: Using z-index**
You can increase the z-index of DIV-A so it appears on top of DIV-B.
```css
div div {
position: relative;
}
div {
z-index: 1; /* set a higher z-index for DIV-A */
}
```
This will ensure that pointer events are sent to DIV-A even when it's covered by DIV-B.
**Method 3: Using transform**
You can use the `transform` property to move DIV-B away from DIV-A, allowing pointer events to reach DIV-A.
```css
div {
position: relative;
}
div div {
z-index: 1; /* set a higher z-index for DIV-A */
transform: translateX(100px); /* move DIV-B 100px away from DIV-A */
}
```
**Method 4: Using event delegation**
You can use event delegation to capture the click event on DIV-A and then dispatch it to DIV-B.
```javascript
document.addEventListener('click', function(event) {
if (event.target === document.querySelector('#div-a')) {
// Dispatch a custom event from DIV-A to DIV-B
new Event('myCustomEvent').dispatchTo(new TargetElement(document.querySelector('#div-b')));
}
});
```
Note: This method requires you to have access to the DOM elements of both DIV-A and DIV-B.
Choose the method that best fits your use case. If you need more control over the layout or positioning, Method 3 using `transform` might be a good choice.
**Method 1: Using pointer-events**
You've already seen this method in the example you provided: https://computer28.com/learn/pointer-events.php
Add the following styles to your DIV-A element:
```css
div div {
pointer-events: none;
}
```
And then add `pointer-events: auto` to the DIV-B element that is covering DIV-A. This will allow pointer events to propagate from DIV-A to DIV-B.
**Method 2: Using z-index**
You can increase the z-index of DIV-A so it appears on top of DIV-B.
```css
div div {
position: relative;
}
div {
z-index: 1; /* set a higher z-index for DIV-A */
}
```
This will ensure that pointer events are sent to DIV-A even when it's covered by DIV-B.
**Method 3: Using transform**
You can use the `transform` property to move DIV-B away from DIV-A, allowing pointer events to reach DIV-A.
```css
div {
position: relative;
}
div div {
z-index: 1; /* set a higher z-index for DIV-A */
transform: translateX(100px); /* move DIV-B 100px away from DIV-A */
}
```
**Method 4: Using event delegation**
You can use event delegation to capture the click event on DIV-A and then dispatch it to DIV-B.
```javascript
document.addEventListener('click', function(event) {
if (event.target === document.querySelector('#div-a')) {
// Dispatch a custom event from DIV-A to DIV-B
new Event('myCustomEvent').dispatchTo(new TargetElement(document.querySelector('#div-b')));
}
});
```
Note: This method requires you to have access to the DOM elements of both DIV-A and DIV-B.
Choose the method that best fits your use case. If you need more control over the layout or positioning, Method 3 using `transform` might be a good choice.
Author: Wilson Edwards replied at 2025-04-14 01:18:27