javascript functions
Posted in
5529
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:
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
84
This Month
728
This Year
3127
Add Comment
Other Items in javascript functions
Related Search Terms
Other Categories in Code
alpine js apps c css factorio font awesome images linux quick modals sqlite site bugs site updates slick slider sliders testing windows apps apache api apps asp bat bootstrap bootstrap templates charts cookies core css css filters css grid design elements docker domains emoji fancybox fonts foundation framework gimp git html icons ideas image formatting images javascript javascript functions jquery js linux mac misc modals mysql nginx node php php errors php function php functions php simple html dom pi400 python react regex sections simple_html_dom simplepie php site bugs site documentation slick slider sql sqlite ssh sublime svg svg css templates tools virtual box vscode vue webdev windows windows 11 windows commands wordpress