I have the following jQuery code:  $("#file-upload").change(function () {     if (this.files &amp;&amp; this.files[0]) {         $('#cancel-image-upload').html('&lt;button type="button" class="btn btn-warning" id="cancel-upload-button" style="margin-right:15px;"&gt;cancel&lt;/button&gt;');     }     else         $("#image-preview").attr("src", "http://placehold.it/200x150"); });   $('#cancel-upload-button').click(function () {         $("#file-upload").replaceWith('&lt;input type="file" id="file-upload" name="file" accept="image/*"&gt;');     });   What this code does is to display cancel button after file has been chosen, and the button should be able to delete it when clicked. I tried the code above but it didn't work for some reason. Why and how can I fix it? thanks!
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.
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
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!
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?
5844
I have an input type="image". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image is paired with, I setup an event handler for the input-image. Then when the user clicks the image, they get a little popup to add some notes to the data.  My problem is that when a user enters a zero into the text box, I need to disable the input-image's event handler. I have tried the following, but to no avail.  $('#myimage').click(function { return false; });
88861
I don't want to use jQuery, but I'd like to use Ajax to do file uploading. Is that possible?  If so, where can I find information/tutorial on it?
7912
In jQuery I need to do an if statement to see if $this doesn't contain the class '.selected'.  $(".thumbs").hover(function(){  $(this).stop().fadeTo("normal", 1.0); },function(){ $(this).stop().fadeTo("slow", 0.3);  });   Basically when this function is run (on hover) I don't want to perform the fades if the class '.selected' has been appended to the div, this will mean that the image will be at full opacity to signify that it's selected. Searched on Google to no luck even though it's a simple question of how to use an IF statement...
10911
With jQuery, how do I find out which key was pressed when I bind to the keypress event?  $('#searchbox input').bind('keypress', function(e) {});   I want to trigger a submit when ENTER is pressed.  [Update]  Even though I found the (or better: one) answer myself, there seems to be some room for variation ;)  Is there a difference between keyCode and which - especially if I'm just looking for ENTER, which will never be a unicode key?  Do some browsers provide one property and others provide the other one?
21905
I tried to update a jQuery code block that was missing a curly brace. The code is incorrect, but I cannot edit it since changes under 6 characters are not allowed (at least at my level of rep?).  I understand why you don't want to allow minor copy-editing, and I agree that's fine for textual descriptions and regular writing, but 1 character can make a big difference in code.
39221
So, I can create an input button with an image using &lt;INPUT type=&quot;image&quot; src=&quot;/images/Btn.PNG&quot; value=&quot;&quot;&gt;  But, I can't get the same behavior using CSS. For instance, I've tried &lt;INPUT type=&quot;image&quot; class=&quot;myButton&quot; value=&quot;&quot;&gt;  where &quot;myButton&quot; is defined in the CSS file as .myButton {     background:url(/images/Btn.PNG) no-repeat;     cursor:pointer;     width: 200px;     height: 100px;     border: none; }  If that's all I wanted to do, I could use the original style, but I want to change the button's appearance on hover (using a myButton:hover class). I know the links are good, because I've been able to load them for a background image for other parts of the page (just as a check). I found examples on the web of how to do it using JavaScript, but I'm looking for a CSS solution. I'm using Firefox 3.0.3 if that makes a difference.
73078
Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? The submit button is not there. I am using a custom div instead of that.
102093
Whenever I try to flag or close a question here, when clicking the submit button the button gets disabled, three dots animating and nothing really happens.  JS console show a single error:  Flagging:     Uncaught TypeError: Cannot read property 'flagSubmitting' of undefined    Closing:     Uncaught TypeError: Cannot read property 'closeSubmitting' of undefined   Please fix, programming questions and spam are beginning to pile up. :(  Update: appears to work fine from within the review system, but otherwise it's the same on Stack Overflow as well
103753
I know that it's possible to replace the browse button, which is generated in html, when you use input tag with type="file.  I'm not sure what is the best way, so if someone has experience with this please contribute.
77655
I'm looking for some input on how to implement custom eventhandling in jquery the best way. I know how to hook up events from the dom elements like 'click' etc, but I'm building a tiny javascript library/plugin to handle some preview functionality.  I've got a script running to update some text in a dom element from a set of rules and data/user input I got, but now I need that same text shown in other elements that this script can't possibly know of. What I need is a good pattern to somehow observe this script producing the needed text.  So how do I do this? Did I overlook some builtin functionality in jquery to raise/handle user events or do I need some jquery plugin to do it? What do you think is the best way/plugin to handle this?
100032
How exactly do you make an auto-refreshing div with JavaScript (specifically, jQuery)?  I know about the setTimeout method, but is it really a good practice ? Is there a better method?  function update() {     $.get("response.php", function(data) {         $("#some_div").html(data);     });     window.setTimeout("update();", 10000); }
24590
I am using &lt;input type="file" id="fileUpload" runat="server"&gt; to upload a file in an ASP.NET application. I would like to limit the file type of the upload (example: limit to .xls or .xlsx file extensions).   Both JavaScript or server-side validation are OK (as long as the server side validation would take place before the files are being uploaded - there could be some very large files uploaded, so any validation needs to take place before the actual files are uploaded).
9579
What is the difference between HTML &lt;input type='button' /&gt; and &lt;input type='submit' /&gt;?