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

后端 未结 6 1786
闹比i
闹比i 2020-12-29 01:18

The element is:

span    {
    position:absolute;
    float:left;
    height:80px;
    width:150px;
    top:210px;
    left:320px;

    background-color:yello         


        
相关标签:
6条回答
  • 2020-12-29 02:00

    The jQuery you're using is manipulates the DOM, not the CSS itself. Try changing the word span in your CSS to .mySpan, then apply that class to one or more DOM elements in your HTML like so:

    ...
    <span class="mySpan">...</span>
    ...
    

    Then, change your jQuery as follows:

    $(".mySpan").css({ display : inline });
    

    This should work much better.

    Good luck!

    0 讨论(0)
  • 2020-12-29 02:01

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

    0 讨论(0)
  • 2020-12-29 02:04

    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();
    
    0 讨论(0)
  • 2020-12-29 02:04

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

    $("span").removeAttr("style");
    
    0 讨论(0)
  • 2020-12-29 02:05

    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>

    0 讨论(0)
  • 2020-12-29 02:13

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

    or..

    $('#lol').css('display', '')
    
    0 讨论(0)
提交回复
热议问题