Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I just want to disable the ability for a user to click, with the exception of links
$('selector').children().not('a').click(function(e) { return false; });
this doesn't work.. thanks
selector
children only selects the immediate children.
children
To disable all of selector's descendants, use this:
$('selector :not(a)').click(function(e) { e.preventDefault() });
Or, to be a little more efficient, use delegation:
$('selector').on('click', ':not(a)', function(e) { e.preventDefault() });
Add a comment
When you want to disable the user from clicking stuff other than links, simply do this:
$('selector').find(':not(a)').click(function(e){ e.preventDefault() })
It applies to all elements other than links.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
selector.