For example:
<a /*title="need to be comment out"*/>a link</a>
For example:
<a /*title="need to be comment out"*/>a link</a>
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 *@
.
data-
attributes, for example, <a data-xtitle="need to be comment out">a link</a>
, though many best practices, including those by such big frameworks as Angular, disadvise this. –
Clotilde <a<? php /* title="need to be comment out"*/ ?>>a link</a>
. –
Clotilde You can't. Comments can only start and end outside tags.
Some people preprend an x to an attribute name, thus changing it and causing it to be all but ignored (since it is still often visible in the DOM), but this is invalid.
I usually just put _x
at the end of the attribute name. Then the attribute is ignored because it's unknown. So if I wanted to comment out the id
attribute from this element:
<input type="text" name="name" id="name">
I would change it to this:
<input type="text" name="name" id_x="name">
This also has the advantage of being able to search for "_x=
" to find all commented attributes.
-id="name"
–
Outpour This cannot be done, but an attribute can be removed via the removeAttribute(attribute_name)
JavaScript call.
Alternatively, you can prefix the attributes you want removed with a namespace like <a nosuchns:title="nevershown">click</a>
and remove the namespace via JavaScript.
© 2022 - 2024 — McMap. All rights reserved.
//
) were also enabled by this. – Repulsion<!
): Does HTML5 change the standard for HTML commenting? – Repulsion