I added a JS file to my theme in a D7 site and then put code like this:
(function ($) { console.log(1); jQuery('#edit-views-send-from-name').val(''); console.log(2); }(jQuery));
and in Firebug I see the 1 and 2 but the middle line doesn't run. But if I copy and paste that code into the box on the right of Firebug's Console and "Run" it, then it does work, so the code is correct.
There are a bunch of other lines between 1 and 2 that I left out for this post, but they all work when I run it manually and the values being set (and items being hidden) are not set (or shown) by other JS on the page--the value is in the HTML, so it's not as though my JS is competing with some other JS to set these values.
Any ideas why my code isn't working?
Thanks.
Answer is I failed to use "behaviors" and the answer is here: http://drupal.stackexchange.com/a/525
Thanks
On Thu, Oct 3, 2013 at 7:27 PM, Fred Jones fredthejonester@gmail.com wrote:
I added a JS file to my theme in a D7 site and then put code like this:
(function ($) { console.log(1); jQuery('#edit-views-send-from-name').val(''); console.log(2); }(jQuery));
and in Firebug I see the 1 and 2 but the middle line doesn't run. But if I copy and paste that code into the box on the right of Firebug's Console and "Run" it, then it does work, so the code is correct.
There are a bunch of other lines between 1 and 2 that I left out for this post, but they all work when I run it manually and the values being set (and items being hidden) are not set (or shown) by other JS on the page--the value is in the HTML, so it's not as though my JS is competing with some other JS to set these values.
Any ideas why my code isn't working?
Thanks.
You probably need to wait until the DOM is fully loaded before running the script, something like body.onload() or jQuery.ready().
On Thu, Oct 3, 2013 at 11:53 PM, Fred Jones fredthejonester@gmail.com wrote:
Answer is I failed to use "behaviors" and the answer is here: http://drupal.stackexchange.com/a/525
Thanks
On Thu, Oct 3, 2013 at 7:27 PM, Fred Jones fredthejonester@gmail.com wrote:
I added a JS file to my theme in a D7 site and then put code like this:
(function ($) { console.log(1); jQuery('#edit-views-send-from-name').val(''); console.log(2); }(jQuery));
and in Firebug I see the 1 and 2 but the middle line doesn't run. But if I copy and paste that code into the box on the right of Firebug's Console and "Run" it, then it does work, so the code is correct.
There are a bunch of other lines between 1 and 2 that I left out for this post, but they all work when I run it manually and the values being set (and items being hidden) are not set (or shown) by other JS on the page--the value is in the HTML, so it's not as though my JS is competing with some other JS to set these values.
Any ideas why my code isn't working?
Thanks.
-- [ Drupal support list | http://lists.drupal.org/ ]