How to add jQuery file to navigation website? - javascript

I am working with this demo: http://cssdeck.com/labs/setting-active-states-on-sticky-navigations-while-scrolling/
For some reason when I try to recreate it the Java part making the navigation work isn't coming through on my version here: http://cssdeck.com/labs/ydsxavxy
So far I saved out index.html, style.css, and flip.js and attempted to link the CSS and JS in the index.
How can I get my version working like the demo? How is a Java file included outside of CSSDeck? I am not too familiar with how CSSDeck takes the HTML, CSS, and Java and combines them into one page preview.

The version of jQuery you are loading is not correct.
The example that works uses 1.8, and you are loading 1.4:
<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
You can easily know this by looking at your browser console and seeing what errors it's throwing. In your case, the error is as follows:
TypeError: $(...).on is not a function
This usually means your jQuery library is not defined or not supported by the code you're using.

Related

"Uncaught TypeError: a.indexOf is not a function" error when opening new foundation project

I've created a new Foundation 5 project through bash, with foundation new my-project. When I open the index.html file in Chrome an Uncaught TypeError: a.indexOf is not a function error is shown in the console, originating in jquery.min.js:4.
I created the project following the steps on the foundation site, but I can't seem to get rid of this error. Foundation and jQuery look like they are included and linked up correctly in the index.html file, and the linked app.js file is including $(document).foundation();
Does anyone know what is causing this error? and what a solution might be?
This error might be caused by the jQuery event-aliases like .load(), .unload() or .error() that all are deprecated since jQuery 1.8. Lookup for these aliases in your code and replace them with the .on() method instead. For example, replace the following deprecated excerpt:
$(window).load(function(){...});
with the following:
$(window).on('load', function(){ ...});
Please add below jQuery Migrate Plugin
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.4.1.min.js"></script>
This error is often caused by incompatible jQuery versions. I encountered the same error with a foundation 6 repository. My repository was using jQuery 3, but foundation requires an earlier version. I then changed it and it worked.
If you look at the version of jQuery required by the foundation 5 dependencies it states "jquery": "~2.1.0".
Can you confirm that you are loading the correct version of jQuery?
I hope this helps.
I faced this issue too. I was using jquery.poptrox.min.js for image popping and zooming and I received an error which said:
“Uncaught TypeError: a.indexOf is not a function” error.
This is because indexOf was not supported in 3.3.1/jquery.min.js so a simple fix to this is to change it to an old version 2.1.0/jquery.min.js.
This fixed it for me.
One of the possible reasons is when you load jQuery TWICE ,like:
<script src='..../jquery.js'></script>
....
....
....
....
....
<script src='......./jquery.js'></script>
So, check your source code and remove duplicate jQuery load.
I'm using jQuery 3.3.1 and I received the same error, in my case, the URL was an Object vs a string.
What happened was, that I took URL = window.location - which returned an object. Once I've changed it into window.location.href - it worked w/o the e.indexOf error.
It's seems to be funny but no one take consideration of the following.
Discover if you are having a library that requires an old version of jQuery. If you can't discover the version, You can do it commenting and uncommenting every script line until you find it.
Open the library and find the author.
Search in google for an update of the library. 90% you will find it.
Update the reference of your obsolete library that requires and old version of jQuery.
IN ANY CASE NEVER DOWNGRADE YOUR JQUERY VERSION
I solved this by installing the correct version of Jquery that my project required using npm

My HTML is not reading the Javascript file in codeacademy editor

I'm learning some jquery using codeacademy and while everything works great within the codeacademy editor, it doesn't work when I upload to a server.
Here is the html in question:
www.arbabmazumdar.com/kudos.html
and here is the js:
www.arbabmazumdar.com/Web_Files/test.js
what am i doing wrong?
1)
<script type="text/javascript" src="../Web_Files/test.js"></script>
You don't actually need the .. part as resources are loaded relatively (i.e. from the same "directory") to the HTML file. Web_Files/test.js would be enough.
2) Your file loads just fine, but you didn't include jQuery, so it fails:
Uncaught ReferenceError: jQuery is not defined test.js:88
Uncaught ReferenceError: $ is not defined kudos.html:19
When something doesn't work it's good to check for errors in the JavaScript console(using Firebug, Chrome Dev tools or IEs Developer Toolbar, etc.)
You have not yet included jQuery !
Include this in <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
in <head></head>

Javascript plug-in doesnt appear on drupal

i want to put a soundcloud music player (http://stratus.sc/) on my drupalgardens page. i added an external source javascript library and uploaded a js file on the system as it says on the pluging website. all this tru the administration website of drupalgardens. When i check the sourcecode of my webpage it appears like the pluging is on the header. But it doesnt work, i cant see it. i activated all the jquery functions.
bit of sourcecode on header where the pluging seems there:
<script type="text/javascript" src="http://stratus.sc/stratus.js"></script>
<script type="text/javascript" src="http://NAMEOFMYSITE/sites/NAMEOFMYSITE/files/js/js_PRNQJr2GPf-FrbaSuV5IDQ1l6Lfby6e79KpPOUTf5kI.js"></script>
link:
http://bit.ly/10nyAHV
Any suggestions?
Note : The player im talking about is NOT the one that can be seen under the rotating banner. the one im talking about its supposed to be globally on the webpage at its seem on the pluging oficcial webpage
For one you're getting this console error: "Uncaught SyntaxError: Unexpected token < "
Not sure how that script is getting added but just removing the script tags may clear it up.
Even if the frame errors mentioned by KG are unrelated, you have to go clean that all up.
Your script should also be loaded after jquery. Since it looks like you have js aggregation turned on, I don't really know how to determine if drupal is loading things correctly. You can just tell your script to load in the footer instead of header if you're unsure. The links below explain how to do that.
Here are some javascript related resources for Drupal. They sometimes expect things to be handled differently.
The plugin is dependent on jQuery. By default, Drupal 7 loads jQuery 1.4. You may need to use the jQuery Update plugin to use 1.5, 1.7 or 1.8
Drupal Community docs about javascript:
http://drupal.org/node/756722
Drupal javascript API:
http://drupal.org/node/751744
I had a similar issue. Some reasons for a not working player are:
For some reason $ is not known (although jQuery is included). I replaced '$' by 'jQuery' and everything worked fine. That means use jquery(document).ready(... instead of $(document).ready(... and jQuery.stratus({.. instead of $.stratus({...
There is a typo on the stratos.sc web site. It should read $.stratus not $stratus (or jQuery.stratus, see previous hint).
Check that the source stratus.js and the initialisation code is included.
Mixture of https and http might be a good guess as reason for problems, but actually it works (I just tried it). If you can't find the problem, try to use a JavaScript debugger and check the error logs first!

Uncaught TypeError: Cannot call method 'each' of undefined

I have this error while trying to run mediaelement player.
The error is reported at mediaelement-and-player.min.js:44.
Edit: My apologies, I posted this from the mediaelementjs.com Support website.
I was trying to use mediaelement.js to play audio on my website.
Edit 8/2: The interesting thing is that when i load the full mediaelement-and-player.js instead of the minified version, it works fine.
I just dealt with this same issue while trying to use the Drupal module, http://drupal.org/project/mediaelement.
Turns out that a core Drupal javascript file, drupal.js, was calling jQuery.noConflict() which removes the $ variable from being defined in the global scope, hence bringing this bug in mediaelement-and-player.js to light.
This was reported in the issue queue for the mediaelement project and it looks like the fix just got committed: https://github.com/johndyer/mediaelement/pull/570
Most likely you have not loaded the jquery library into your script.
You have to reference the library (a js file) from within the header of your page via url. The url can point to a copy pf jquery you keep local or to a public site.

Undefined is not a function in Backbone.js

I get the error "undefined is not a function" when running this code locally and from a Dropbox public url, http://dl.dropbox.com/u/6862628/backbone.html.
However, when I run it on jsfiddle it works as expected: http://jsfiddle.net/fdKKD/
In short, I'm creating a simple model and a simple view. When I set a property on the model, the view console.log's "render".
I'm seeing the same behavior in Chrome 17 and Safari, Mac.
This is driving me nuts. Would appreciate some help.
Backbone requires either jQuery or Zepto to be loaded before Backbone if you intend to do any DOM manipulation (i.e. if you use a view). Your HTML includes things in this order:
Underscore.
Backbone.
jQuery.
So Backbone doesn't know if it should use jQuery or Zepto when it loads and you end up with an undefined value being used a function. Your original jsfiddle uses jQuery in the sidebar so jQuery will be loaded by jsfiddle before your <script> tags are hit, so Backbone sees jQuery, uses it, and everything works. If you switch to "No-Library (pure JS)":
http://jsfiddle.net/ambiguous/pzgW7/
then you'll see your error again. If you include jQuery first:
http://jsfiddle.net/ambiguous/C32Gd/
things will work.

Categories