I want to get the body element of an html using jquery and then disable the vertical scrolling?
The jQuery selector finds particular DOM element(s) and wraps them with jQuery object. For example, document. getElementById() in the JavaScript will return DOM object whereas $('#id') will return jQuery object.
The Document Object Model (DOM) elements are something like a DIV, HTML, BODY element on the HTML page. A jQuery Selector is used to select one or more HTML elements using jQuery. Mostly we use Selectors for accessing the DOM elements.
$(document. body) is using the global reference document to get a reference to the body , whereas $('body') is a selector in which jQuery will get the reference to the <body> element on the document .
To get HTML content of an element using jQuery, use the html() method. The html() method gets the html contents of the first matched element.
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 id="c_1" >CLick Me</a>
$('#c_1');
or by class
with the prefix .
<a class="classname">Click Me</a>
$('.classname');
for more information read http://api.jquery.com/category/selectors/ 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.
http://reference.sitepoint.com/css/overflow
or the proper reference http://www.w3.org/TR/CSS2/visufx.html
sorry if this is too technical, but one day you would have to learn about these :)
You 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
:
Example Here
document.body.style.overflow = 'hidden';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With