Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "generated" attribute seen in some HTML tag used for?

Tags:

html

I saw it used in a HTML label tag but I have a feeling that it can be used with most HTML tags. I can kinda guess what it means. But I am more curious about what's the benefit of using it. I tried to google for some reference about it but couldn't find any, so I come to you experts. Thanks.

Example:

<label for="first_name" generated="true" class="error">This field is required.</label>
like image 337
tamakisquare Avatar asked Jul 20 '11 23:07

tamakisquare


People also ask

What are HTML attributes used for?

HTML attributes can be used to change the color, size, and other features of HTML elements. For example, you can use an attribute to change the color or size of a font for a text element or the width and height for an image element.

What are the 3 types of attribute in HTML?

HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes: Usually the required and optional attributes modify specific HTML elements.


1 Answers

You could use it as a hook for JavaScript and/or CSS.

For example...

CSS

label[generated=true] {
   color: #ccc;
}

JavaScript

var labels = document.getElementsByTagName('label');

for (var i = 0, length = labels.length; i < length; i++) {
    if (labels[i].getAttribute('generated') === 'true') {
       // Do something.
    }
}

It is often used on JavaScript generated elements, such as the label elements created by the jQuery Validation plugin.

You could use jQuery to clean up generated elements with...

$('*[generated=true]').remove();
like image 90
alex Avatar answered Oct 12 '22 01:10

alex