remove attribute display:none; so the item will be visible

145,345

Solution 1

For this particular purpose, $("span").show() should be good enough.

Solution 2

$('#lol').get(0).style.display=''

or..

$('#lol').css('display', '')

Solution 3

The removeAttr() function only removes HTML attributes. The display is not a HTML attribute, it's a CSS property. You'd like to use css() function instead to manage CSS properties.

But jQuery offers a show() function which does exactly what you want in a concise call:

$("span").show();

Solution 4

You should remove "style" attribute instead of "display" property :

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

Solution 5

If you are planning to hide show some span based on click event which is initially hidden with style="display:none" then .toggle() is best option to go with.

$("span").toggle();

Reasons : Each time you don't need to check whether the style is already there or not. .toggle() will take care of that automatically and hide/show span based on current state.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Toggle" onclick="$('#hiddenSpan').toggle();"/>
<br/>
<br/>
<span id="hiddenSpan" style="display:none">Just toggle me</span>

Share:
145,345

Related videos on Youtube

mt0s
Author by

mt0s

looking forward...

Updated on October 23, 2021

Comments

  • mt0s
    mt0s over 2 years

    The element is:

    span    {
        position:absolute;
        float:left;
        height:80px;
        width:150px;
        top:210px;
        left:320px;
    
        background-color:yellow;
    
        display:none;                 //No display                  
        border: 3px solid #111;
    }
    

    I use this code to remove the display so it can be visible,

    $("span").removeAttr("display");

    but it does not work. Is the method I'm using valid or is there an other way to get the result?

  • Errore Fatale
    Errore Fatale over 8 years
    If you remove style, you completely reset the style. I don't think that someone who opens this question wants to do this.
  • André Kelling
    André Kelling over 4 years
    most correct solution. as simple show() will add inline style display and not fallback to CSS rules
  • Destabilizator
    Destabilizator about 4 years
    toggle also adds inline style attribute