3475
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
125
This Month
178
This Year
1071

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
A.A. Milne’s Winnie-the-Pooh: “If you live to be a hundred, I want to live to be a hundred minus one day so I never have to live without you.”
A.A. Milne
Random CSS Property

border-inline-color

The border-inline-color CSS property defines the color of the logical inline borders of an element, which maps to a physical border color depending on the element's writing mode, directionality, and text orientation. It corresponds to the border-top-color and border-bottom-color, or border-right-color and border-left-color property depending on the values defined for writing-mode, direction, and text-orientation.
border-inline-color css reference