简体   繁体   中英

How to display text using display property in CSS

I want to display the text using display property in css

 echo '<script type="text/javascript">document.getElementById("amt1").style.display= "none";</script>';

I want to display text message instead of display ="none" in amt1 id

1. You have to use .innerHTML like below:

echo '<script type="text/javascript">document.getElementById("amt1").innerHTML= "add your message here";</script>';

2. If message is already there and you just want to show that div then change none to block

echo '<script type="text/javascript">document.getElementById("amt1").style.display= "block";</script>';

3. if you want to add message dynamically as well as you want to show the div too, then:

echo '<script type="text/javascript">
    document.getElementById("amt1").innerHTML= "add your message here";
    document.getElementById("amt1").style.display= "block";
    </script>';

Sample javascript code snippet example to understand how it will work

 document.getElementById("amt1").innerHTML= "This message added in div through javascript .innerHTML method!!!"; document.getElementById("amt1").style.display= "block"; 
 #amt1 { border: 1px solid grey; font-size: 30px; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="amt1" style="display:none;"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM