2

I have a parent container loading in a child container which has javascript src pointing to a library. When the child is loaded, the src library does not run.
I tried getScript() after callback but this does not have any affect.

The library is a color picker: http://jscolor.com/

Any suggestions please?

parent.html:

<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript">
      $(function(){
        $('#rec').load('child.html', function(){
          $.getScript("js/jscolor.js");
        });
      });
    </script>
  </head>
  <body>
    <div id='rec'></div>
  </body>
</html>

child.html:

<script type="text/javascript" src="js/jscolor.js"></script>
<input class="color" value="66ff00">
10
  • What do you see in the dev tools? Commented Jul 19, 2013 at 17:53
  • 6
    My psychic debugging skills tell me that you have a 404 due to relative path issues. Commented Jul 19, 2013 at 17:54
  • @SLaks do you mean console? the child is loaded but the JS does not work. Commented Jul 19, 2013 at 17:54
  • @SLaks i dont see a 404, when i place the content of child in parent for testing it all works Commented Jul 19, 2013 at 17:58
  • 1
    Not even jQuery codes works inside your child.html ? Commented Jul 19, 2013 at 18:11

1 Answer 1

5

jscolor.js needs to loaded before document is completly loaded because it attach stuffs to input element using onload event of document, in your case document is already loaded when you load jscolor.js. So call jscolor.init again after $.getScript("js/jscolor.js") has loaded the js file.

$(function(){
$('#rec').load('child.html', function(){
   $.getScript("js/jscolor.js", function(data, textStatus, jqxhr) {
       jscolor.init();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.