Use of the ID attribute in the link tags

0

Is it appropriate to use the ID attribute in the tags? In what cases could I use it?

What versions of HTML would support this type of reference? In this case, does the ID always have the selector function?

In what other tags can we use ID and that have no recurring use of this attribute as?

These questions come from a sample of HTML code I was seeing that had the following:

<link href="link/pro/css/file.css" rel="stylesheet" id="theme"/>
    
asked by anonymous 07.06.2016 / 01:01

1 answer

2

Is it appropriate to use the ID attribute in the tags? In which cases could I use it?

Yes it is appropriate as long as there is only one element with the ID. Therefore, care must be taken in its use. Nowadays, with jQuery widely accepted, it is much more common to use classes, even to access JavaScript elements, since selecting an element via class is as easy as via ID:

Via ID : elemento = $("#id")

Via class : elemento = $(".classe")

Which versions of HTML would support this type of reference? In this case, does the ID always have the selector function?

All HTML elements can have an ID. HTML, because it is an extremely semantic language, does not impute a sense of functionality directly, but rather of meaning. The ID identifies the element within the document. The features can be of the most diverse. For example, you could use the ID to even identify a product in the database:

<li class="product" id="product-323"></li>

Note: I used a prefix instead of leaving the number pure. This is to avoid duplicate IDs on the page. Another object, such as <a id="category-323"></a> could end up having the same attribute ID by accident.

    
07.06.2016 / 02:10