Control whether the display property is displayed through javaScript and jquery respectively

js

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>display</title>
    <script type="text/javascript">
        function hidetext()  
        {  
        var mychar = document.getElementById("con");
         mychar.style.display="none" ; //Do not display, hide
        }  
        function showtext()  
        {  
        var mychar = document.getElementById("con");
        mychar.style.display="block" ; //Display, not hide
        }
    </script>
</head>
<body>  
    <h1>JavaScript</h1>   
    <form>
       <input type="button" onclick="hidetext()" value="隐藏内容" />
       <input type="button" onclick="showtext()" value="显示内容" />
    </form>
</body>
</html>

jquery

//hide

$("#id").css('display','none'); 

//show

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

or 

$("#id")[0].style.display = 'none'; 

$("#id") returns JQuery 
it is a collection that must have display property

$("#id").show() display:block, $("#id").hide() means display:none; $("#id").toggle() toggles the visible state of the element. If the element is visible, switch to hidden; if the element is hidden, switch to visible.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325734759&siteId=291194637