I have a button which is generated in a function via a mustache JS template.  {{#attributes}}     &lt;a class="button--small btn" data-selector="{{selector}}"&gt;{{title}}&lt;/a&gt; {{/attributes}}   and a sample output of that is  &lt;a class="button--small btn" data-selector=".news"&gt;More News&lt;/a&gt;   However, I am trying to execute another jquery function when this button is clicked but regardless of whether I use .click(function() { }); or .bind it doesn't seem to work? Even a console.log doesn't print so I'm not getting into the right conditions.  Here is the script:  function lazyload(selector) {     $("a[data-selector^='"+selector+"']").bind("click", function(e) {             e.preventDefault();             loadNews(selector);     }); }  $(document).ready(function(){    lazyload(".news"); // CALL FUNCTION READY FOR USAGE });
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
36235
I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector.  I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is?  EDIT: The attribute filters allow you to select based on patterns of an attribute value.
85015
if you create html layout like so  &lt;ul&gt;      &lt;li class='a'&gt;&lt;/li&gt;      &lt;li class='b'&gt;&lt;/li&gt;      &lt;li class='a'&gt;&lt;/li&gt;      &lt;li class='b'&gt;&lt;/li&gt;      &lt;li class='a'&gt;&lt;/li&gt;      &lt;li class='b'&gt;&lt;/li&gt;      &lt;li class='a'&gt;&lt;/li&gt;      &lt;li class='b'&gt;&lt;/li&gt; &lt;/ul&gt;   and try to select odd elements with 'a' class like so $$('.a:odd') you will get empty array, and if you do $$('.a:even') you will get all four li elements with 'a' class.. It really strange.. But im new to mootools, maybe im doing something wrong..    So my question is how to select first and third li elements with a class. I know that i can do it with function like this  $$('.a').filter(function(item, index) { return index%2; }  but its too complicated for such small task as selecting odd or even elements..
121438
I am using jQuery library in my visual force page, but I've faced a major problem when I tried to use tabs "apex:tabPanel".  &lt;script src="{!$Resource.jQuery}"&gt;&lt;/script&gt; &lt;!-- If I delete this script the tabs work !! --&gt;  &lt;apex:tabPanel tabClass="activeTab" inactiveTabClass="inactiveTab"&gt;   &lt;apex:tab label="Tab#1" id="tab1"&gt;&lt;/apex:tab&gt;   &lt;apex:tab label="Tab#2" id="tab2"&gt;&lt;/apex:tab&gt; &lt;/apex:tabPanel&gt;   I get a "JS" errors in the console when I try to click on any tab, but if I delete jQuery library it works. So I guess there is a conflict between jQuery and apex:tabPanel functionality.    Here's what I got in the console   Uncaught ReferenceError: initViewstateTab is not defined  Uncaught TypeError: Object [object Object] has no method 'dispatchEvent'  Uncaught ReferenceError: initViewstateTab is not defined  event.returnValue is deprecated. Please use the standard event.preventDefault() instead. Uncaught TypeError: Object [object Object] has no method 'hasClassName'  Uncaught TypeError: Cannot call method 'replace' of undefined
48996
I'd like to implement a simple AJAX function locally that allows me to autocomplete node titles of already existing nodes as the user types. To that end, I need the ability to have an API that I can search on node titles. The problem is that when I output raw JSON, it comes surrounded by tags. So, no matter what I do, I keep getting...  &lt;html&gt;     &lt;head&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;pre style="word-wrap: break-word; white-space: pre-wrap;"&gt; {json here}&lt;/pre&gt;     &lt;/body&gt; &lt;/html&gt;   I've tried implementing a custom page template that only outputs content already, that produced the same results. Here is how I am currently doing this, in my module file...  &lt;?php  /**  * Implementation of hook_menu()  */ function content_relation_menu() {     $items = array();     $items['api'] = array(         'title' =&gt; 'Search',         'page callback' =&gt; 'content_relation_get',         'access callback' =&gt; TRUE,         'type' =&gt; MENU_CALLBACK,     );      return $items; }  function content_relation_get($term = '') {     drupal_add_http_header('Content-Type', 'application/javascript; utf-8');     $var = json_encode(         db_query("SELECT nid,title FROM {node} WHERE title LIKE :title LIMIT 5", array(":title" =&gt; $term.'%'))-&gt;fetchAll()     );     echo $var;     exit(0); }   How can I return JUST raw JSON?
23360
I want to use jQuery inside a firefox extension, I imported the library in the xul file like this:  &lt;script type="application/x-javascript" src="chrome://myExtension/content/jquery.js"&gt; &lt;/script&gt;   but the $() function is not recognized in the xul file neither do the jQuery().  I googled about the problem and found some solutions but no one did work with me:    I've also tried to pass the 'content.document' object(which refrences the 'document' object) as the context parameter to the jQuery function like this:  $('img',content.document);   but still not working, does any one came across this problem before?
17578
In Mootools, I'd just run if ($('target')) { ... }.  Does if ($('#target')) { ... } in jQuery work the same way?
32885
I have some html like this:  &lt;div id="1"&gt;     &lt;p&gt;         Volume = &lt;input type="text" /&gt;         &lt;button rel="3.93e-6" class="1" type="button"&gt;Check answer&lt;/button&gt;     &lt;/p&gt;     &lt;div&gt;&lt;/div&gt; &lt;/div&gt;   and some JS like this:  $("button").click(function () {     var buttonNo = $(this).attr('class');     var correct = Number($(this).attr('rel'));      validate (Number($("#"+buttonNo+" input").val()),correct);     $("#"+buttonNo+" div").html(feedback); });   What I'd really like is if I didn't have to have the class="1" on the button (I know numeric classes aren't valid, but this is a WIP!), so I could determine buttonNo based on the id of the parent div. In real life there are multiple sections looking like this.   How do I find the id of the div parenting the button. What would be a more semantic way to store the answer in the button code. I want to make this as foolproof as possible for a non programmer to copy and paste without breaking things!
114452
I am trying to add JavaScript and CSS files to one node type page from my template.php file but it is not working.  Here is my template.php code:   &lt;?php // $Id: template.php,v 1.13 2010/12/14 01:04:27 dries Exp $  function mttheme_preprocess_html(&amp;$variables) {   $node = node_load(arg(1));   if ($node-&gt;type = 'sales_team_page') {     drupal_add_css('misc/jquery.fancybox-1.3.4.css');     drupal_add_js('misc/jquery.mousewheel-3.0.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-1.3.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-calls.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );   } }   Does anyone know why it is not working?
75034
I have an input form that lets me select from multiple options, and do something when the user changes the selection. Eg,  &lt;select onChange="javascript:doSomething();"&gt;   &lt;option&gt;A&lt;/option&gt;   &lt;option&gt;B&lt;/option&gt;   &lt;option&gt;C&lt;/option&gt; &lt;/select&gt;   Now, doSomething() only gets triggered when the selection changes.  I want to trigger doSomething() when the user selects any option, possibly the same one again.  I have tried using an "onClick" handler, but that gets triggered before the user starts the selection process.  So, is there a way to trigger a function on every select by the user?  Update:  The answer suggested by Darryl seemed to work, but it doesn't work consistently. Sometimes the event gets triggered as soon as user clicks the drop-down menu, even before the user has finished the selection process!
88408
I have this Visualforce code snippet in a page:  &lt;apex:outputLink value="javascript:if (window.confirm('Are you sure?')) DeleteQuoteLineItem('{!LineItem.QuoteLineItem.Id}');"&gt;     Del &lt;/apex:outputLink&gt;  &lt;apex:actionFunction action="{!DeleteQuoteLineItem}" name="DeleteQuoteLineItem" reRender="content"&gt;     &lt;apex:param value="test"/&gt; &lt;/apex:actionFunction&gt;   The two methods I'm using for testing are:  public void DeleteQuoteLineItem(String RecordID) {     System.debug('method with a paramater');     System.debug(RecordID); }  public void DeleteQuoteLineItem() {     System.debug('method without a parameter'); }   Everytime I click on the link to execute the apex:actionFunction, it's calling the DeleteQuoteLineItem() method without any parameter. I looked online and it seems like I need to create a class attribute and use assignTo= in my apex:param to populate it accordingly.  Is it possible to prevent this behavior and use standard method parameters, so I don't have to create class attributes? I want to work on a clean and optimized codebase, preventing unnecessary variable scope (so no class attribute when it's not required) and improve code re-usability by staying context agnostic.  Thanks
62205
I'm trying to include a Javascript gallery () on my new Drupal 8 site and wrote a field formatter for this purpose.   Now I need to add the jQuery lightGallery to pages using this field formatter and call the library when the page is ready. I am confused about how I am supposed to do this, though.   I defined the library in the module containing my field formatter, but I'm not sure how I attach it only on sites that contain the field.   The documentation of the library uses the jQuery $(document).ready function to call the libary, how would that work inside a Drupal module?
67914
I am creating an element with document.createElement(). Now how can I pass it to a function that only takes a Jquery object?  $("#id")    I can not use it, as the element has not been rendered in the page yet.
120639
I'm trying to put search results into a div with ajax. The issue is I'm getting errors saying undefined function have_posts() when the the search template is accessed. It also took issue with get_header() which was in the search-results.php but I took it out. Here's how I have it setup.    &lt;div id="my_search"&gt;    &lt;form role="search" method="get" id="searchform" action="http://myurl.com/" &gt;     &lt;input type="text" value="" name="s" id="s" /&gt;     &lt;input type="submit" id="searchsubmit" value="Search" /&gt;    &lt;/form&gt;   &lt;/div&gt;   &lt;div id="results"&gt;&lt;/div&gt;   &lt;script type="text/javascript"&gt;     $(document).ready(function(){     $("#searchsubmit").click(function(e){      e.preventDefault();      var search_val=$("#s").val();       $.post('http://mysite.com/wp-content/themes/beta/search-results.php',{search_string:search_val},function(data){         if(data.length&gt;0){             $("#results").html(data);         }      });     });       });   &lt;/script&gt;   And here is the search-results.php template. I'm wondering if maybe I'm not passing the search results to the template.  &lt;ul&gt;  &lt;?php if (have_posts()) : while (have_posts()) : the_post();  ?&gt;   &lt;li&gt;&lt;a title="Permalink to this post" href="&lt;?php echo get_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;   &lt;?php endwhile; endif; ?&gt;  &lt;?php if (!have_posts()) { echo('&lt;li&gt;No results to show.&lt;/li&gt;'); } ?&gt; &lt;/ul&gt;
104313
I really want to run a simple code in my template file.  E.g. if I put somethign like this in my page.php:  &lt;script type="text/javascript"&gt;     jQuery(document).ready(function($) {         alert("Hello world!");     }); &lt;/script&gt;   It's not working.  But simple javascript is working:  &lt;script type="text/javascript"&gt;         alert("Hello world!"); &lt;/script&gt;   Why is jQuery blocked in WP to be included in template files?  and maybe more important question     WHERE IN THE WP SETTINGS CAN I RE-ENABLE THIS?   I know I can use wp_register_script etc. but in my scenario I need to paste simple javascript code in the template files.  How to allow load jQuery code snippets in WP template's file too?  And why is it even blocked?
6080
I'm new to both JavaScript and . In YUI library examples, you can find many uses of this construct:  (function() {     var Dom = YAHOO.util.Dom,     Event = YAHOO.util.Event,     layout = null,         ... })();   I think the last couple of parentheses are to execute the function just after the declaration.  ... But what about the previous set of parentheses surrounding the function declaration?  I think it is a matter of scope; that's to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses?
104708
I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like:   &lt;div&gt;   &lt;!-- some html --&gt;   &lt;script type="text/javascript"&gt;     /** some javascript */   &lt;/script&gt; &lt;/div&gt;   I'm inserting the whole thing into the DOM, but the JavaScript isn't being run.  Is there a way to run it?    Some details: I can't control what's in the script block (so I can't change it to a function that could be called), I just need the whole block to be executed.  I can't call eval on the response because the JavaScript is within a larger block of HTML.  I could do some kind of regex to separate out the JavaScript and then call eval on it, but that's pretty yucky.  Anyone know a better way?