B
B
Begetan2011-04-10 18:45:57
HTML
Begetan, 2011-04-10 18:45:57

How is it guaranteed to comment out any piece of HTML?

Good afternoon habra community!

An interesting, and as it turned out, non-trivial question arose. It is necessary to insert lines in the html text in such a way that an arbitrary block with any valid content can be commented out.

Option 1. Write naturally:

<!-- 

тут наш код для отключения

-->


And immediately a bummer: It is allowed to add other tags inside the comment, nested comments (when one comment is located inside another) are not allowed .

Our comment is broken by any nested comment (check it out for yourself)!

Next I found a wonderful tag
<comment> </comment>
It turned out that it is only supported by IE, so I didn’t even look at how it works.

The last idea was:
<script type="text/javascript"> /*

тут наш код для отключения

*/ </script>

Almost exactly what you need ... until the first nested script! If it is inside, then everything after the closing tag is uncommented.

What way do you know?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
A
Anatoly, 2011-04-10
@taliban

I would
advise you to cut the required piece of code and paste it into another file with the same name. file.

G
Gibbzy, 2011-04-11
@gibbzy

<?php /*
комментарий
*/?>

well as an option)

S
Sergey, 2011-04-10
@butteff

comment
I don’t even know, I was puzzled by the question =)

M
MT, 2011-04-11
@MTonly

In the long run, it makes sense to abandon the software system that forces you to face such tasks.

S
sainnr, 2011-04-10
@sainnr

If this option is suitable, then you can add script tags:

<script> 
/* разметка */ 
// или так
</script>

N
Nodge, 2011-04-11
@Nodge

So far I see the only option: jsfiddle.net/6Xr2w/1/
1. Comment inside the script with single-line comments
2. For nested </script> tags, replace brackets with < and >
3. Wrap the script of the first level in <![CDATA[...]]>, for validity =)

B
barsu4ok, 2013-06-21
@barsu4ok

friends, how are you?
<?php /*
comment
*/?> the
first options also do not work
with display: none - in general, a risk

G
Gitley, 2020-11-25
@Gitley

<!-- Коммент ВРЕМЕННЫЙ

<! Коммент постоянный 1 >
<div class="a">
  <p>Lorem ipsum dolor sit, amet.</p>
</div>

<! Коммент постоянный 2 >
<div class="b">
  <p>Lorem ipsum dolor sit amet.</p>
</div>	

<! Коммент постоянный N >
<div class="c">
  <p>Lorem ipsum dolor sit amet.</p>
</div>	
 
 -->

Here I googled it. I just started, in the sense of a beginner, so I did not check in all browsers, only in Chrome. I don’t know if such comments will pass validation, because I heard about validation, but didn’t google it;) But sublime syntax highlighting even adequately displays such comments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question