Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change CSS value when page has loaded?

Tags:

jquery

css

Is it possible to change a value of a css style after the page has finished loading?

For example I need to change a division that is display:block to display:none after the page has finished loading?

Is this possible in jQuery and if so how do I implement it?

like image 712
Vince P Avatar asked Sep 24 '26 22:09

Vince P


2 Answers

Checkout the ready() event, and the css() method.

Look at the list of possible selectors to see how to target your element.

$(document).ready(function () {
    $('selectorForYourElement').css('display', 'none');
});

Edit:

To answer your question, you can either combine the selector with the :gt() selector, or use the slice() method (preferred).
$(document).ready(function () {
    $('selectorForYourElement').slice(1).css('display', 'none');
});

Or

$(document).ready(function () {
    $('selectorForYourElement:gt(0)').css('display', 'none');
});
like image 152
Matt Avatar answered Sep 26 '26 11:09

Matt


$('selector').css({
    display: 'none'
});
like image 34
Naftali Avatar answered Sep 26 '26 12:09

Naftali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!