I want to get the body element of an html using jquery and then disable the vertical scrolling?
93 Answers
Try this...
$('body,html').css('overflow','hidden');
the ,html allows you to also include the <html> because some browsers may use that as the base as oppose to the <body> tag so it helps treating both as if they were one.
helpful any tag should be selected like so $('a'); or $('body');
an element can be selected by id using the prefix # so
<a >CLick Me</a>
$('#c_1'); or by class with the prefix .
<a>Click Me</a>
$('.classname'); for more information read as for the scroll bars they are controlled by css, you could simply go on a css file and do the following.
body, html {overflow: hidden;}
the overflow parameter allows you to control what happens when content overflow the assigned width and hight.
sorry if this is too technical, but one day you would have to learn about these :)
2You can get the body element with: $("body") then disable the scrollbars with CSS
$("body").css("overflow", "hidden"); Since nobody mentioned this, it's pretty easy to select the body element without jQuery.
It's simply:
document.body; And based on your question, you would disable vertical scrolling by setting overflow: hidden:
document.body.style.overflow = 'hidden';