5

I've come 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" ??

dendini
  • 3,842
  • 9
  • 37
  • 74

4 Answers4

1

It 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.

rnevius
  • 26,578
  • 10
  • 58
  • 86
1

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.

Justinas
  • 41,402
  • 5
  • 66
  • 96
1

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.compile($('script.say_hello.' + language).html()); 
$('#header').append(say_hello_template(user));

I hope it helps

Sonalkumar sute
  • 2,565
  • 2
  • 17
  • 27
1

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?

Community
  • 1
  • 1
ak-SE
  • 980
  • 1
  • 7
  • 27