Use of the ID attribute in <link> tags

Asked

Viewed 196 times

0

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

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

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

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

<link href="link/pro/css/file.css" rel="stylesheet" id="theme"/>

1 answer

2

Is it appropriate to use the ID attribute in 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 should be taken in its use. Nowadays, with jQuery widely accepted, it is much more common to use classes, even to access Javascript elements, because selecting an element via class is as easy as via ID:

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

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

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

All HTML elements can have an ID. HTML, being 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 the most diverse. For example, you could use the ID to identify even a product in the database:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.