0

How to remove the style with jQuery or JavaScript in order to display the div element?

  <div style="display: none">display something </div>

If you know ,please share with me . Thanks

PS:Before ,I have tried with jquery.show(), but the effect is a big blank over there

andyqee
  • 3,175
  • 3
  • 21
  • 24

8 Answers8

2

Try like

$('div').css('display','block');

Better you give an class or id to the specific div and try like

Using Id :

$('#div_id').css('display','block');

Using Class :

$('.div_class').css('display','block');
GautamD31
  • 28,552
  • 10
  • 64
  • 85
1

You better assign some id to your div to make it unique and keep the change upto desired element. You can use style property of javascript DOM object to access display or other sub-property.

<div style="display: none" id="id" >display something </div> 

Using javascript

document.getElementById('id').style.display = 'block';

Using JQuery, you can use id selector

$('#id').css('display','block');

If you just want to change display property you can use show / hide method instead.

$('#id').show();
Adil
  • 146,340
  • 25
  • 209
  • 204
0
document.getElementById('id of the div').style.display = 'block';

should give an Id to the div

Another method is

$('div').css('display','block');
Leo T Abraham
  • 2,407
  • 4
  • 28
  • 54
0

first you need to identify the div for that give the div an ID or a class attribute

<div style="display: none" id="mydiv">display something </div>

then jQuery

jQuery(function($){
    $('#mydiv').show()
})
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

jQuery provide shortcut for this:

$('div').show();
rgtk
  • 3,240
  • 1
  • 30
  • 36
0

You can show it with the jQuery show method, like this:

$('div').show();

This will show all divs on your page. If you want to only show this particular div, you could give it an id, like this:

<div style="display: none" id="myDiv">display something </div>

And then show it like this:

$('#myDiv').show();
Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
0

If you just want to show the div you can do this:

$("div").show();

If you want to remove the style tag completely:

$("div").removeAttr("style");

Note: Id recommend giving your div an id or class otherwise either of the above 2 options will do it to all div's not just this one.

e.g: <div id="myDiv" style="display: none">display something </div>

then you would change that div liek this:

$("#myDiv").show();
azzy81
  • 2,261
  • 2
  • 26
  • 37
0

To remove an style effect :

$('div').css('display','');

From jQuery doc :

$( "#mydiv" ).css( "color", "" ) — removes that property from an element if it has already been directly applied.

See doc

Damien
  • 8,889
  • 3
  • 32
  • 40