Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change CSS display none or block property using jQuery?

How can I change CSS display none or block property using jQuery?

like image 607
DEVOPS Avatar asked Aug 27 '10 08:08

DEVOPS


People also ask

Can we change CSS property value using jQuery?

You can change CSS using the jQuery css() method which is used for the purpose of getting or setting style properties of an element. Using this method you can apply multiple styles to an HTML all at once by manipulating CSS style properties.

Can jQuery manipulate CSS?

The jQuery CSS methods allow you to manipulate CSS class or style properties of DOM elements. Use the selector to get the reference of an element(s) and then call jQuery css methods to edit it. Important DOM manipulation methods: css(), addClass(), hasClass(), removeClass(), toggleClass() etc.


2 Answers

The correct way to do this is to use show and hide:

$('#id').hide(); $('#id').show(); 

An alternate way is to use the jQuery css method:

$("#id").css("display", "none"); $("#id").css("display", "block"); 
like image 152
djdd87 Avatar answered Sep 25 '22 13:09

djdd87


There are several ways to accomplish this, each with its own intended purpose.


1.) To use inline while simply assigning an element a list of things to do

$('#ele_id').css('display', 'block').animate(.... $('#ele_id').css('display', 'none').animate(.... 

2.) To use while setting multiple CSS properties

$('#ele_id').css({     display: 'none'     height: 100px,     width: 100px }); $('#ele_id').css({     display: 'block'     height: 100px,     width: 100px }); 

3.) To dynamically call on command

$('#ele_id').show(); $('#ele_id').hide(); 

4.) To dynamically toggle between block and none, if it's a div

  • some elements are displayed as inline, inline-block, or table, depending on the Tag Name

$('#ele_id').toggle();

like image 39
SpYk3HH Avatar answered Sep 22 '22 13:09

SpYk3HH