I have problem with dynamic generated buton from typeahead twitter:  templates: { empty: [     "&lt;button type='button' class='btn btn-danger btn-sm form-add' data-toggle='modal' data-target='#form-add' data-title='Add' data-text='abc' data-form-action='' data-parent-id=" + $(self).data("parent-id") + "&gt;Add&lt;/button&gt;" ].join("\n"), suggestion: function(data) {     return "&lt;p&gt;" + data.name + "&lt;/p&gt;"; }}   and I would like send data-parent-id to my modal on click event on button Add and this not work.  $("button.form-add").on("click", function(e) { console.log("typeahead"); });   What is wrong ?  Regards
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.
112471
On my team, we usually do string concatentation like this:  var url = // some dynamically generated URL var sb = new StringBuffer(); sb.append("&lt;a href='").append(url).append("'&gt;click here&lt;/a&gt;");   Obviously the following is much more readable:  var url = // some dynamically generated URL var sb = "&lt;a href='" + url + "'&gt;click here&lt;/a&gt;";   But the JS experts claim that the + operator is less performant than StringBuffer.append(). Is this really true?
932
Suppose I attach an blur function to an HTML input box like this:  &lt;input id="myInput" onblur="function() { ... }"&gt;&lt;/input&gt;   Is there a way to get the ID of the element which caused the blur event to fire (the element which was clicked) inside the function? How?  For example, suppose I have a span like this:  &lt;span id="mySpan"&gt;Hello World&lt;/span&gt;   If I click the span right after the input element has focus, the input element will lose its focus. How does the function know that it was mySpan that was clicked?  PS: If the onclick event of the span would occur before the onblur event of the input element my problem would be solved, because I could set some status value indicating a specific element had been clicked.  PPS: The background of this problem is that I want to trigger an AJAX autocompleter control externally (from a clickable element) to show its suggestions, without the suggestions disappearing immediately because of the blur event on the input element. So I want to check in the blur function if one specific element has been clicked, and if so, ignore the blur event.
25094
I have HTML code like this :  &lt;div&gt;        &lt;a&gt;Link A1&lt;/a&gt;        &lt;a&gt;Link A2&lt;/a&gt;        &lt;a&gt;Link A3&lt;/a&gt; &lt;/div&gt;  &lt;div&gt;        &lt;a&gt;Link B1&lt;/a&gt;        &lt;a&gt;Link B2&lt;/a&gt;        &lt;a&gt;Link B3&lt;/a&gt; &lt;/div&gt;   When user clicks a link from above HTML, I want to get the jQuery object of the corresponding &lt;a&gt; element, and then manipulate its sibling. I can't think of any way other than creating an ID for each &lt;a&gt; element, and passing that ID to an onclick event handler. I really don't want to use IDs.   Any suggestions?
27208
I have an HTML string representing an element: '&lt;li&gt;text&lt;/li&gt;'. I'd like to append it to an element in the DOM (a ul in my case). How can I do this with Prototype or with DOM methods?  (I know i could do this easily in jQuery, but unfortunately we're not using jQuery.)
119899
I am refering  to render dynamic component in LWC. But it is giving error createElement is not defined.  Have any one idea how to render dynamic component. Alternative of createComponent method of Aura framework.
80948
I have an HTML page with a typical structure:  &lt;html&gt;   &lt;head&gt;    &lt;script src="..." &gt;&lt;/script&gt;    &lt;style&gt;...&lt;/style&gt;   &lt;/head&gt;   &lt;body&gt;    content   &lt;/body&gt;   &lt;script&gt;     var success_callback = function(data) {       // REPLACE PAGE CONTENT &amp; STRUCTURE WITH "data"     }     ajax(url, params, success_callback);   &lt;/script&gt; &lt;/html&gt;   Do you think it is possible ?  I've already tried to give the html tag an id and doing $(id).replace(data); with no success.  Don't ask me why, but that is what I need (I'm working with a special "mashup builder" site... it is a long story).  EDIT : I forgot to say that scripts in the received content have to be executed, even external scripts included using &lt;script src="..."&gt;.
25453
I have created a 'control' using jQuery and used jQuery.extend to assist in making it as OO as possible.  During the initialisation of my control I wire up various click events like so  jQuery('#available input',              this.controlDiv).bind('click', this, this.availableCategoryClick);   Notice that I am pasing 'this' as the data argument in the bind method. I do this so that I can get at data attached to the control instance rather from the element that fires the click event.   This works perfectly, however i suspect there is a better way  Having used Prototype in the past, I remember a bind syntax that allowed you to control what the value of 'this' was in the event.  What is the jQuery way?
20484
Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of:   $("&lt;div&gt;&lt;/div&gt;");   However, I'm getting the feeling that this isn't the best or the most efficient method of doing this. What is the best way to create elements in jQuery from a performance perspective?   has the benchmarks to the suggestions below.
49974
How can you reliably and dynamically load a JavaScript file?  This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand.  The client that uses the component isn't required to load all the library script files (and manually insert &lt;script&gt; tags into their web page) that implement this component - just the 'main' component script file.  How do mainstream JavaScript libraries accomplish this (Prototype, jQuery, etc)?  Do these tools merge multiple JavaScript files into a single redistributable 'build' version of a script file?  Or do they do any dynamic loading of ancillary 'library' scripts?  An addition to this question: is there a way to handle the event after a dynamically included JavaScript file is loaded?  Prototype has document.observe for document-wide events. Example:  document.observe("dom:loaded", function() {   // initially hide all containers for tab content   $$('div.tabcontent').invoke('hide'); });   What are the available events for a script element?
81099
I am tryin to create expand and collapse functionality between pageblocks.The scenario is when i click the collapse button in one pageblock ,it should render another pageblock.How this can be achieved ? I tried using java script but the pageblock is not displaying properly. My current code is   &lt;apex:page &gt;   &lt;apex:includeScript value="{!$Resource.jqueryCollapse}"/&gt;   &lt;apex:includeScript value="{!$Resource.jqueryCollapse1}"/&gt;    &lt;apex:includeScript value="{!$Resource.jqueryCollapse2}"/&gt;    &lt;apex:form &gt;    &lt;html&gt;    &lt;head&gt;     &lt;script type="text/javascript"&gt;      $(function(){     $(".header").click(function () {        alert("Loopafe");    $header = $(this);        $content = j$header.next();         $content.slideToggle(100, function () {                 $header.text(function () {                     return $content.is(":visible") ? $(this).attr("src",      "https://c.ap1.visual.force.com/resource/1404298250000/Minus") : $(this).attr("src", "https://c.ap1.visual.force.com/resource/1404298250000/plusimg");     });  });     });  });  &lt;/script&gt;  &lt;style&gt;    .container .content {   display: none;  padding : 5px;  }  &lt;/style&gt; &lt;/head&gt; &lt;apex:pageBlock &gt; &lt;apex:pageBlockSection columns="10" collapsible="True" &gt;            &lt;div class="container"&gt;     &lt;img   src="XXg"class ="   header " /&gt;           &lt;div class="content"&gt;          &lt;apex:pageBlock &gt;            &lt;apex:pageBlockSection columns="5"  &gt;         &lt;apex:outputLabel value="Collapse"  id="theSecond1"/&gt;         &lt;apex:inputText /&gt;         &lt;/apex:pageBlockSection&gt;                     &lt;/apex:pageBlock&gt;    &lt;/div&gt;    &lt;/div&gt;         &lt;apex:outputText value="First" id="theFirst"/&gt;         &lt;apex:InputText /&gt;      &lt;/apex:pageBlockSection&gt;     &lt;/apex:pageBlock&gt; &lt;body&gt;  &lt;/body&gt;  &lt;/html&gt;    &lt;/apex:form&gt;   &lt;/apex:page&gt;
24403
By default, the web form is displayed with &lt;?php print drupal_render($form['submitted']); ?&gt; .  I need to make a small edit and add class="btn" to the submit button.  I can change its value with $form['actions']['submit']['#value'] = "click to become a member";  But I couldnt find a way to add the class.  Please help!  Thank you
92799
Several of my pages use both JQuery and Protoype. Since I upgraded to version 1.3 of JQuery this appears to be causing problems, because both libraries define a function named '$'.  JQuery provides a function noConflict() which relinquishes control of $ to other libraries that may be using it. So it seems like I need to go through all my pages that look like this:  &lt;head&gt;           &lt;script type="text/javascript" src="/obp/js/prototype.js"&gt;&lt;/script&gt;     &lt;script type="text/javascript" src="/obp/js/jquery.js"&gt;&lt;/script&gt; &lt;/head&gt;   and change them to look like this:  &lt;head&gt;           &lt;script type="text/javascript" src="/obp/js/prototype.js"&gt;&lt;/script&gt;     &lt;script type="text/javascript" src="/obp/js/jquery.js"&gt;&lt;/script&gt;     &lt;script type="text/javascript"&gt;         jQuery.noConflict();         var $j = jQuery;     &lt;/script&gt; &lt;/head&gt;   I should then be able to use '$' for Prototype and '$j' (or 'jQuery') for JQuery. I'm not entirely happy about duplicating these 2 lines of code in every relevant page, and expect that at some point somebody is likely to forget to add them to a new page. I'd prefer to be able to do the following    Create a file jquery-noconflict.js which "includes" jquery.js and the 2 lines of code shown above Import jquery-noconflict.js (instead of jquery.js) in all my JSP/HTML pages   However, I'm not sure if it's possible to include one JS file in another, in the manner I've described? Of course an alternate solution is simply to add the 2 lines of code above to jquery.js directly, but if I do that I'll need to remember to do it every time I upgrade JQuery.
122548
I have a submit button in my form and I want to implement it using ajax:  function myid_user_page_form(){      drupal_add_library('system', 'drupal.ajax');     $form = array();     $form['id'] = array(        '#type' =&gt; 'fieldset',        '#title' =&gt; t('ID Information'),        '#prefix' =&gt; '&lt;div id="myid_search_id_number_wrapper"&gt;',        '#suffix' =&gt; '&lt;/div&gt;'    );       $form['submit'] = array(       '#type' =&gt; 'button',       '#value' =&gt; 'Save',          '#ajax' =&gt; array(          'event' =&gt; 'click',          'callback' =&gt; 'myid_user_page_form_ajax_submit',          'wrapper' =&gt; 'myid_search_id_number_wrapper'       ),        '#attributes' =&gt; array(         'id' =&gt; 'myid_save',                    ), );  function myid_user_page_form_ajax_submit($form, &amp;$form_state) {      watchdog('Wow','Wow'); }   After executing the code above, the page still has it's refresh after it's clickfunctionality. The ajax doesnt work and no Wow message log in my watchdog table from my database, which means the ajax callback function isn't called. Where am I missing?
15530
By adding use-ajax to a link we can open a modal using the Drupal ajax library as per the . E.g. &lt;a class=&quot;use-ajax&quot;      data-dialog-options=&quot;{&amp;quot;width&amp;quot;:400}&quot;      data-dialog-type=&quot;modal&quot;      href=&quot;/node/1&quot;&gt;     First article displayed in modal dialog. &lt;/a&gt;  This will use the ajax library to fetch node/1 and then display it in a modal. There is also a  which allows opening modals using JavaScript. E.g. var myDialog  = Drupal.dialog(ADOMElement, settings); myDialog.show();  The problem with this API is you need to pass in a existing DOM element. My question is can I trigger opening a modal with JavaScript and utalise the internal Drupal ajax library to actually fetch the content? E.g Can I do something like this? var myDialog  = Drupal.dialog('/node/1', {useAjax: true}); myDialog.show();  I could just create an html link as per my first code block, hide it with css, and then trigger a click on it with JS but this seems a bit hacky - there must be a way to trigger this action using pure JS.
122028
I have a requirement where I use  in Lightning and I have implemented the same as below code. I created a Lightning Tab from this component and used in Lightning Experience. Component: &lt;aura:component implements=&quot;force:appHostable&quot;&gt;     &lt;ltng:require scripts=&quot;/resource/treeTable/treeTableJS.js&quot; afterScriptsLoaded=&quot;{!c.loadScripts}&quot;/&gt;     &lt;aura:attribute name=&quot;temp&quot; type=&quot;String&quot; default=&quot;none&quot; /&gt;     &lt;aura:attribute name=&quot;content&quot; type=&quot;String[]&quot; default=&quot;item1,item2,item3,item4&quot; /&gt;     &lt;table id=&quot;table&quot;&gt;         &lt;tbody&gt;             &lt;tr data-tt-id=&quot;parent&quot;&gt;                 &lt;td&gt;&lt;ui:button label=&quot;Click&quot; press=&quot;{!c.selectClick}&quot; /&gt;&lt;/td&gt;                 &lt;td&gt;Content&lt;/td&gt;             &lt;/tr&gt;             &lt;aura:iteration items=&quot;{!v.content}&quot; var=&quot;item&quot; indexVar=&quot;index&quot;&gt;                 &lt;tr data-tt-id=&quot;{!'child'+index}&quot; data-tt-parent-id=&quot;parent&quot;&gt;                     &lt;td&gt;&lt;/td&gt;                     &lt;td&gt;{!item}&lt;/td&gt;                 &lt;/tr&gt;             &lt;/aura:iteration&gt;         &lt;/tbody&gt;     &lt;/table&gt; &lt;/aura:component&gt;  Controller: ({     loadScripts : function(component, event, helper) {         $(&quot;#table&quot;).treetable({                 expandable: true             }, {                 force: true             }, {                 initialState: &quot;collapsed&quot;             });     },      selectClick : function(component, event, helper) {         if(component.get(&quot;v.temp&quot;)===&quot;none&quot;){             component.set(&quot;v.temp&quot;,&quot;plus&quot;);             $(&quot;#table&quot;).treetable(&quot;expandNode&quot;, &quot;parent&quot;);         } else{             component.set(&quot;v.temp&quot;,&quot;none&quot;);             $(&quot;#table&quot;).treetable(&quot;collapseNode&quot;, &quot;parent&quot;);          }     }, })  Now about the issue, when I use this in Lightning tab first time it works (meaning straight forward scenario), but now from this page I navigate to any standard record page (be it Accounts record page) or even Home page and come back to this lightning tab, it does not work. We have to refresh the page to make it work again. Any resolve so that we don't need to refresh the page? Please help. Note: Lightning Locker service is disabled.
81854
When I define an object of a class using new like this  $blah = new Whatever();   I get autocomplete for $blah. But how do I do it when I have $blah as a function parameter? Without autocomplete I am incomplete.  Edit: How do I do it if it's in an include and PDT or Netbeans can't figure it out? Is there any way to declare types for variables in PHP?