3486
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
136
This Month
189
This Year
1082

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
“If you just sit and observe, you will see how restless your mind is. If you try to calm it, it only makes it worse, but over time it does calm, and when it does, there’s room to hear more subtle things. You see so much more than you could see before. It’s a discipline; you have to practice it.”
Steve Jobs
Random CSS Property

min-width

The min-width CSS property sets the minimum width of an element. It prevents the used value of the width property from becoming smaller than the value specified for min-width.
min-width css reference