Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide or remove comments in browser view page source?

Tags:

comments

html

I'm working on a site. It contains a lot of comments. When a user click the view page source in any browser, I want to hide or remove the comments from the HTML.

Is this possible? If possible, could someone say a way to achieve it.

like image 607
Gopinath Perumal Avatar asked Jan 31 '14 10:01

Gopinath Perumal


People also ask

How do I make comments invisible in HTML?

To create hidden comments in HTML, we add <! --- tag and end it with -- >. Whatever comes inside this tag it is hidden. These comments allow us to easily understand the code.

Are comments visible on websites?

Note: Comments are not displayed by the browser, but they can help document your HTML source code.

Are comments ignored by browser?

Comment is a piece of code which is ignored by any web browser.


1 Answers

At the moment I decided to use php to create html and jquery comments to hide them in view source

like

<input type="submit" value="Submit">
<?php //this is comment regarding input ?>

Possibly it affects performance... but found no other way

Regarding jquery one note.

//$('#upper_level_id0').css('color', 'red');<?php //works ?>
$('#upper_level_id'+index).remove();

In this example $('#upper_level_id'+index).remove(); does not work.

$('#upper_level_id0').css('color', 'red');<?php //works ?>
//$('#upper_level_id0').css('color', 'red');
<?php //works ?>
$('#upper_level_id'+index).remove();

But in this example all works. So conclusion that <?php comment better tos start in new line

like image 153
Andris Avatar answered Sep 16 '22 21:09

Andris