So first some background. This code is to be used as a bookmarklet and I've done testing with it as a bookmarklet and as code pasted into the javascript console in Chrome. Either way I'm getting the same error, Uncaught ReferenceError: $ is not defined.
Now before anyone tells me that I don't have jQuery embedded anywhere in my code, this is to be used on a website that has jQuery, and when I paste the exact same code in just not inside of a setInterval() it works fine, so here's my very simple code.
javascript:window.setInterval(function() { $("#fbutton").click() }, 5000);
On Chrome in the developer tools, $ is a shortcut for document.querySelector. So that is why it is valid in the console.
What you are running is actually
document.querySelector("#fbutton").click();
https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference#selector
Related
Rails will not let me run JS code, I have these errors
1)
2)
whenever you add JS code, the errors appear.
Some idea why this happening?
Just because you're getting error highlights in your IDE, doesn't necessarily mean your code is wrong. Try running your server, navigate to your site from your browser, and check the developer console. Do you still see javascript errors?
This warning (it is not an error) is being displayed because your IDE thinks that the variable $ is not defined in your code. However, it is not able to find out that $ is a global variable defined in the jQuery library, imported a few lines before.
The IDE is just saying that the presence of that variable is not guaranteed unless you properly import the needed libraries to make it exist (jQuery in this case). Your code should work properly. In order to identify errors in your javascript code, I would recommend you to use the built in console in the web browser.
I'm using Google Analyticator and my website is http://gestionalemagazzinoonline.it/
You can see the error in the javascript console.
I think that is the suspected file:
https://github.com/wp-plugins/google-analyticator/blob/master/google-analyticator.php
The problem is also if i disable the plugin, or if i change the source code i don't see the changes (maybe there's a cache?).
How can I fix?
Script tags are meant to write javascript in them, and not html.
You have a script block inside a script block. Remove that, and it will work all fine.
I built out a demo page using Timeline JS and it works fine within a regular HTML file (See Example Here). However, now that I am using it with ExpressionEngine platform (v 2.9.2), I get a javascript error and the area where the timeline should appear is blank (See Here).
The js error message is "Uncaught ReferenceError: createStoryJS is not defined." I'm not well versed with javascript so I do not know what that means or how to correct it. Please help.
Per RainerJ on Experts-Exchange, I just needed to add the following reference. It works like a charm now
I have a live site and I open it on Internet explorer and right click on page and click on view source and copy all code from it and paste it on vs2010->Newwebsite and when i run my site on vs2010 an error occur.
Microsoft JScript runtime error: '$' is undefined
I don't understand what I do. Kindly suggest me.
waiting for reply.
Thanks
You'd fix that by including jQuery!
Add the following to your page
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
However, it sounds like just an error in Visual Studio, and if it works when viewing the page in a browser, it shouldn't be an issue.
First verify that jQuery is in fact being loaded.
if (window.jQuery) {
alert("jQuery is loaded!");
}
If that works, then you are most likely using something like jQuery.noconflict() to remove the alias $ for jQuery.
Sorry, new to Firebug. I really find being able to run javascript in the Firebug console window helpful. However, I don't seem to be able to run jQuery calls in the console. For example, in my executing javascript in my page, I may make the call to get a value:
jQuery('#an_element_value').text()
However, I cannot execute this in the console. In order to retrieve this value from the page in the console I have to execute:
document.getElementById('an_element_value').innerHTML
Is there a way to execute jQuery calls and reference page elements through jQuery in the Firebug console?
Like others have said, it wont work unless you have jquery included on the page. However, you can easily include jQuery on any page with this bookmarklet: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
Just put this before your code in firebug console:
include("jquery");
more...