I've e across the following code for Datatables jquery plugin:
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
What is the purpose of class="init" ??
I've e across the following code for Datatables jquery plugin:
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
What is the purpose of class="init" ??
Share Improve this question asked Sep 22, 2014 at 8:03 dendinidendini 3,9529 gold badges42 silver badges75 bronze badges 8- Who knows... Look in the css maybe? – elclanrs Commented Sep 22, 2014 at 8:04
- Maybe it's for selecting certain scripts? @elclanrs Scripts wouldn't show anyways. – Scimonster Commented Sep 22, 2014 at 8:05
- 4 stackoverflow./questions/5506610/… – user733421 Commented Sep 22, 2014 at 8:05
- How can you apply css style to a script inclusion??? – dendini Commented Sep 22, 2014 at 8:05
-
1
In HTML5,
<script>
supports Global Attributes (e.g.class
). It IS valid in HTML5: w3/TR/html5/scripting-1.html#the-script-element – rnevius Commented Sep 22, 2014 at 8:14
4 Answers
Reset to default 1It just invalidates your code.
class
is not allowed on script, in HTML4 and XHTML.
Although it IS valid in HTML5, as the <script>
tag supports global attributes (which includes class
).
Check out the specification.
You can select that script
tag just like any other tag in DOM. Purpose? From CSS "visualization" where code block is, to JS/jQuery dynamic code generation.
Somewhere it could be used is dynamically selecting one from many script snippets to use elsewhere. Like javascript templating language
<script class="say_hello english" type="text/x-handlebars-template">
<p>Hello {{name}}</p>
</script>
<script class="say_hello german" type="text/x-handlebars-template">
<p>Hallo {{name}}</p>
</script>
...
var say_hello_template = Handlebars.pile($('script.say_hello.' + language).html());
$('#header').append(say_hello_template(user));
I hope it helps
In the javascript file, which you have included using tag like <script type="text/javascript" language="javascript" class="init" src="../../js/jFile.js"></script>
may contains the coding which refers to the class init. This type of class seems like a CSS coding, but it is a reference to javascript.
Open the javascript in a text editor and search for the term "init". The coding may also be defined as mentioned in the article Is there a benefit to putting a class on a script tag?