How to make entire Div clickable in javascript
How to make entire Div clickable in javascript
In this session, we will try our hand at solving the "How to make entire Div clickable in javascript".
There are lots of method available to make a div clickable in Javascript. But here we have to get the link of anchor tag which is the inner element of div tag and redirect the user to the link using window.location.-
Make a div clickable using inner anchor tag with javascript
<!-- HTML --> <div class="myBox"> blah blah blah. <a href="http://google.com">link</a> </div> <!-- javascript --> <script> $(".myBox").click(function() { window.location = $(this).find("a").attr("href"); return false; }); </script>
You can make the entire div clickable using the value of href attribute of anchor tag which is child element of div.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Javascript
- How to set href value of anchor tag in javascript
- ReferenceError: Cannot access 'myFunction' before initialization
- How can I add a key/value pair to a JavaScript object
- Execute function with condition in javascript
- How to echo array in Javascript
- How to get data from localstorage in javascript
- How to validate input type file size in javascript
- How to display an image in Javascript onclick
- Animating numbers counting Javascript
- How to add key/value pair to existing form data
- Uncaught TypeError: Assignment to constant variable
- How to open modal after redirect
- Remove hostname from URL in javascript
- How to pass array as arguments to function in javascript
- Short-circuits conditionals
- Prism js horizontally overflowing its container
- Get multiplication in javascript using array input
- Custom slider js
- Apex bar chart - fill bar color with gradient on hover
- Cropper js with multiple images
- Javascript get data-id attribute value
- Javascript set timeout function with example code
- Get hostname from URL in javascript
- Copy one array to another in javascript
- Multidimensional array example javascript