简体   繁体   中英

How to hide an element from the source when it is hidden?

When using display: none you can still see the contents of the element in the source code.

Is there a way to prevent this using JavaScript, PHP or some other approach?

You havent gave much infomation about if you mean view source or inspect element, what you can do is set the insides of the element to nothing, by doing this:

<script>document.getElementById('myElement').innerHTML = "";</script>

When viewing the element from inspect element, the insides of your element will simply be gone,

The downside is its still viewable on view-source, i cant think of a fix to this

i wouldn't recommend doing it this way because if your making some kind of admin dashboard the dashboard's code is publicly visible, if you want to hide it perminantly use PHP as anything in the

<?php
//Code
?>

is only viewable to the server, not the client.

If your interested in PHP i would recommend having a look at this source: https://www.w3schools.com/php/php_intro.asp

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