---
# System prepended metadata

title: 點擊div中的任意位置時，重新定向到該連接值
tags: [jQuery]

---

---
tags: jQuery
---
###### tags: `jQuery`
# 點擊div中的任意位置時，重新定向到該連接值
### HTML 程式碼
```python=1
<div class="myBox">
  blah blah blah.
  <a href="https://www.google.com.tw/">link</a>
</div>
```

### JS 程式碼
```python=1
$(".myBox").click(function() {
  window.location = $(this).find("a").attr("href"); 
  return false;
});
```

<iframe height="265" style="width: 100%;" scrolling="no" title="vYXbqMG" src="https://codepen.io/juest/embed/vYXbqMG?height=265&theme-id=dark&default-tab=css,result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
  See the Pen <a href='https://codepen.io/juest/pen/vYXbqMG'>vYXbqMG</a> by gt.juest
  (<a href='https://codepen.io/juest'>@juest</a>) on <a href='https://codepen.io'>CodePen</a>.
</iframe>