Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin crashes when js files are called from html's head tag instead of body #50

Closed
noum opened this issue Jul 27, 2016 · 2 comments
Closed

Comments

@noum
Copy link

noum commented Jul 27, 2016

All in the title. Although, I only tested the jQuery version, not the simple JS version

This doesn't work and return the following error: Uncaught TypeError: Cannot read property 'style' of null jQueryColorPicker.min.js:3:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link href="jqColor.css" media="all" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
        <script type="text/javascript" src="jQueryColorPicker.min.js"></script>
        <script type="text/javascript" src="main.js"></script>
    </head>
    <body>
    </body>
</html>

main.js is where I do cp_picker = new ColorPicker({...}) on DOM ready.

On the other hand, this works great:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link href="jqColor.css" media="all" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
    </head>
    <body>
        <script type="text/javascript" src="jQueryColorPicker.min.js"></script>
        <script type="text/javascript" src="main.js"></script>
    </body>
</html>

Where could be the problem please ?

@PitPik
Copy link
Owner

PitPik commented Jul 27, 2016

Hi @nomentsoa-andrianjatovo ,

well, this seems to be an error in main.js. You describe that you call the picker on DOM-ready but I think that there is something going wrong:
Maybe wrap your code in main.js in a $(function() { ... }); wrapper and try again.

Let me know if it works.
Cheers

@noum
Copy link
Author

noum commented Jul 28, 2016

@PitPik
Already contained it in a (function($) { ... })(jQuery);. But since putting js files before </body> is good for me too, then it's no longer an issue, also I just wanted to be sure it doesn't come from the plugin. So I guess we can close this.

Thanks BTW, sorry for the trouble.

@noum noum closed this as completed Jul 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants