Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to bind a click event to a div's left border in jquery?

I have a div

<div id="preview">
</div>

Is there any way to bind a click event to this div's left border?

Thanks in advance.

like image 824
Sanjay Kumar N S Avatar asked Jun 09 '15 07:06

Sanjay Kumar N S


1 Answers

div {
    height:100px;
    border:4px solid black;
    padding:10px;
}

Please try this method

$('div').click(function(e){
   if(  e.offsetX < 5){
        alert('clicked on the left border!');
    }
});

Edit - Better version

$('div').click(function(e){
    if(  e.offsetX <= parseInt($(this).css('borderLeftWidth'))){
       alert('clicked on the left border!');
    }
});
like image 117
Rino Raj Avatar answered Oct 23 '22 13:10

Rino Raj