3

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!

3
  • Try $('div_selector').off('click') Commented Nov 9, 2016 at 22:40
  • .myDiv { pointer-events: none; } Commented Nov 9, 2016 at 22:44
  • Please read How to Ask. Key phrases: "Search, and research" and "Explain ... any difficulties that have prevented you from solving it yourself". Commented Nov 9, 2016 at 22:54

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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

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

    return false
});

1 Comment

This doesn't seem to work for some reason... jsfiddle.net/rohanssrao/t0y4w2mo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.