
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
- Trim the leading and trailing comma from string in Javascript
- Uncaught SyntaxError: Identifier 'CODE' has already been declared
- How to preview a word document in HTML using javascript
- How to check file is an image in javascript using filename
- Hide div on click outside of element in javascript/jQuery
- Json stringify
- Uncaught TypeError: Cannot read property 'addEventListener' of undefined
- JavaScript test() Method
- Javascript set timeout function with example code
- Javascript get data-id attribute value
- Deault order of record in datatable
- Uncaught TypeError: Assignment to constant variable
- How to show and hide placeholder text
- Remove property from object in javascript
- Execute function with condition in javascript
- How to fixed bootstrap navbar at top on scroll
- How to validate input type file size in javascript
- Input type file styling
- Uncaught TypeError: $(...).summernote is not a function
- Get multiplication in javascript using array input
- Generate 6 digit random number in javascript
- Get hostname from URL in javascript
- How to validate empty space in textbox in Javascript
- ReferenceError: Cannot access 'myFunction' before initialization
- Uncaught TypeError: Illegal invocation