3466
2:58 am, May 2, 2023
 

make clickable element with clickable class open link in new window

makes an element with a link into a clickable element. This finds the 1st a tag in the target element and then opens the link in a _blank tab.

Then if you have an element that you want to be clickable and open in a _blank tab just add the class clickable-blank.

Combination of this:

https://kruxor.com/view/code/5olJi/using-javascript-to-open-a-link-in-the-same-window-and-in-a-new-window-or-tab-open-link/ 

and this:

https://kruxor.com/view/code/Q92MB/make-clickable-element-with-clickable-class/ 

window.open('https://kruxor.com/','_blank');

HTML

<div class='clickable-blank some-padding'>
<a href='https://kruxor.com/view/code/ZJEyX/'>Im a Link</a>
But this whole div should be clickable and open in a _blank tab
</div>

CSS

.some-padding {
padding:20px;
border-radius:10px;
background:#999;
}
.clickable-blank {
cursor:pointer;
}

Javascript

$(document).ready(function(){
$('.clickable-blank').click(function(){
    var a_ele = $(this).find('a').attr('href');
  	window.open(a_ele,'_blank');
    return false;
});
});
Im a Link But this whole div should be clickable and open in a _blank tab

View Statistics
This Week
116
This Month
169
This Year
1062

No Items Found.

Add Comment
Type in a Nick Name here
 
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
There is a qualitative and quantitative difference between a day that begins with a little exercise, a book, meditation, a good meal, a thoughtful walk, and the start of a day that begins with a smartphone in bed.
Unknown
Random CSS Property

::backdrop

The ::backdrop CSS pseudo-element is a box the size of the viewport which is rendered immediately beneath any element being presented in fullscreen mode. This includes both elements which have been placed in fullscreen mode using the Fullscreen API and <dialog> elements.
::backdrop css reference