3453
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
103
This Month
156
This Year
1049

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


seren spirit :(
Random CSS Property

border-block-end-style

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