lundi 1 janvier 2018

CDATA inside JavaScript

There is the simple script in head:

<head>
<script type="text/javascript" src="/themes/default-bootstrap/js/jquery.maskedinput.js"></script>
    <script type="text/javascript">
         $('#div').mask('+7(999) 999-9999');
    </script>
</head>

On the site page script doesnt work, if I run it with console - it works. No errors. jQuery is connected. I try to put the script before :

<head>
     <script type="text/javascript" src="/themes/default-bootstrap/js/jquery.maskedinput.js"></script>
</head>
<body>
     <div id="div"></div>
     <script type="text/javascript">
          $('#div').mask('+7(999) 999-9999');
     </script>
</body>

Also I tried to put script into the file. In Chrome DevTools script shown in one line and looks like that:

<head>
     <script type="text/javascript">/* <![CDATA[ */;$('#div').mask('+7(999) 999-9999');/* ]]> */</script>
</head>

What could be the reason? Can CDATA affect the operation of the script and why it is automatically added?




Aucun commentaire:

Enregistrer un commentaire