Can I set ids and classes in styles, scripts, etc?

1

Can I set ids and classes to style , script , etc?

Example:

<style class="teste" id="teste">
/*
  Meu codigo aqui
*/
</style>
    
asked by anonymous 18.08.2017 / 16:56

2 answers

1

Can you, have you already tested?

Example below.

document.getElementById('teste-style').innerHTML = 'p{color: #e41;}';

document.getElementById('teste-script').innerHTML = 'alert("Foo!");';
<style class="teste" id="teste-style">
/*
  Meu codigo aqui
*/
</style>
<script id="teste-script"></script>
<p>Texto aqui!</p>
    
18.08.2017 / 17:02
1

It can. Whenever in doubt you can consult the MDN which is considered the official documentation. There are all the attributes that each tag allows. In this case the two tags allow these attributes because they are part of global attributes .

For <style> .

For <script> .

    
18.08.2017 / 17:00