All In One Script
MENU

Event binding on dynamically created elements?

by 5:37:00 AM
undefined
Event binding on dynamically created elements? I have a bit of code where I am looping through all the select boxes on a page and binding a .hoverevent 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 (jQuery Live Query Plugin), but

How to move an element into another element?

by 5:35:00 AM
undefined
How to move an element into another element? I would like to move one DIV element inside another. For example, I want to move this (including all children): <div id="source"> ... </div> into this: <div id="destination"> ... </div> so that I have this: <div id="destination"> <div id="source"> ... </div> </div> Answer: You may want to use the appendTo function (which adds to the end of the element): $("#source").appendTo("#destination"); Alternatively you could use the prependTo function (which adds to the beginning of the element): $("#source").prependTo("#destination"); http://stackoverflow.com/questions/1279957/how-to-move-an-element-into-another-element

$(document).ready equivalent without jQuery

by 5:32:00 AM
undefined
$(document).ready equivalent without jQuery I have a script that uses $(document).ready, but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency. How can I implement my own $(document).ready functionality without using jQuery? I know that using window.onload will not be the same, as window.onload fires after all images, frames, etc. have been loaded. Answer: There is a standards based replacement,DOMContentLoaded that is supported by over 98% of browsers, though not IE8: document.addEventListener("DOMContentLoaded", function(event) { //do work }); jQuery's native function is much more

Get current URL in JavaScript?

by 5:30:00 AM
undefined
Get current URL in JavaScript? I am using jQuery. How do I get the path of the current URL and assign it to a variable? Example URL: http://localhost/menuname.de?foo=bar&amp;number=0 Answer: To get the path, you can use: var pathname = window.location.pathname; // Returns path only var url = window.location.href; // Returns full URL http://stackoverflow.com/questions/406192/get-current-url-in-javascript

Abort Ajax requests using jQuery

by 5:28:00 AM
undefined
Abort Ajax requests using jQuery Using jQuery, how can I cancel/abort an Ajax request that I have not yet received the response from? Answer: Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort(). See the documentation: abort Method (MSDN). Cancels the current HTTP request. abort() (MDN). If the request has been sent already, this method will abort the request. var xhr = $.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg );

Disable/enable an input with jQuery?

by 5:21:00 AM
undefined
Disable/enable an input with jQuery? $input.disabled = true; or $input.disabled = "disabled"; Which is the standard way? And, conversely, how do you enable a disabled input? Answer: jQuery 1.6+ To change the disabled property you should use the .prop() function. $("input").prop('disabled', true); $("input").prop('disabled', false); jQuery 1.5 and below The .prop() function doesn't exist, but .attr() does similar: Set the disabled attribute. $("input").attr('disabled','disabled'); To enable again, the proper method is to use .removeAttr() $("input").removeAttr('disabled'); In any version of jQuery You can always rely on the actual DOM object and is probably a little faster

Instagram