Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment HTML tag attribute in HTML source code?

Tags:

html

For example:

<a /*title="need to be comment out"*/>a link</a> 
like image 869
lovespring Avatar asked Jan 20 '11 07:01

lovespring


People also ask

How can we write comment along with HTML code?

In HTML, a comment is text enclosed within < ! ╌ ╌> tags. This syntax tells the browser that they are comments and should not be rendered on the front end. Thanks to the comments tag, you can leave notes to remind yourself where you left off in the build process.

What is comment tag in HTML?

The comment tag is used to insert comments in the source code. Comments are not displayed in the browsers. You can use comments to explain your code, which can help you when you edit the source code at a later date. This is especially useful if you have a lot of code.


1 Answers

The W3C documentation suggests it cannot be done:

Note that comments are markup.

This basically means that a <!-- ...> comment tag is just like any other tag, so <a <!--title="need to be comment out"-->>a link</a> is as wrong as <a <span></span>>a link</a>.

For quick hacking I believe a common option is to rename that attribute. While you obtain invalid HTML, you can temporarily remove the attribute:

<a xtitle="need to be comment out">a link</a> 

If you happen to be using a server-side language, you can also use its own comment syntax. For instance, in PHP you can do this:

<a <?php/*title="need to be comment out"*/?>>a link</a> 

... which generates this HTML:

<a >a link</a> 

... and in ASP.NET you can use <%-- Comment goes here --%> while the ASP.NET MVC Razor syntax is @* Comment goes here *@.

like image 132
Álvaro González Avatar answered Oct 05 '22 22:10

Álvaro González