Kyle Brown
Kyle Brown

Reputation: 303

CSS/JS - Disable click events but allow scrolling on DIV

Pretty much title, I would like to allow scrolling in a DIV, but disable click events. Does anyone know any way this could be accomplished?

Thank you!

Upvotes: 3

Views: 4628

Answers (2)

Aloxord
Aloxord

Reputation: 1

var myDiv = document.querySelector('#myDiv');

myDiv.addEventListener('click', function(){

    return false
});

Upvotes: 0

masterpreenz
masterpreenz

Reputation: 2290

For me create a special class that prevents click events then wrap these element(s) with a scrollable container.

<div class="scrollable-div">
    <div class="child-div noclick">
    //anything else
    </div>
 </div>

and your js would look like

$('.noclick').click(function(event){
    // prevent default behavior of click
    event.preventDefault();
    return false;
});

Hope that helps

Upvotes: 1

Related Questions