3520
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
36
This Month
223
This Year
1116

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
When I realized that, no individual step is hard in any process. Building this airport I'm standing in right now started with a guy writing the architectural plans on paper. That's not hard for him to do. Then laying the first beam isn't had. The whole thing is really hard. So, just take each step kind of piece by piece and when I was able to do that and stop trying to chase this prize and started putting in the work, things just started coming together.
Unknown
Random CSS Property

:first-child

The :first-child CSS pseudo-class represents the first element among a group of sibling elements.
:first-child css reference