All In One Script
MENU

$(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

Convert form data to JavaScript object with jQuery

by 5:31:00 AM
undefined
Convert form data to JavaScript object with jQuery. How do I convert all elements of my form to a JavaScript object? I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do not want a string, as returned by $('#formid').serialize();, nor do I want the map returned by $('#formid').serializeArray(); Answer: serializeArray already does exactly that. You just need to massage the data into your required format: function objectifyForm(formArray) {//serialize data function var returnArray

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&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 );

jQuery scroll to element

by 5:24:00 AM
undefined
jQuery scroll to element I have this input element: <input type="text" class="textfield" value="" id="subject" name="subject"> Then I have some other elements, like other text inputs, textareas, etc. When the user clicks on that input with #subject, the page should scroll to the last element of the page with a nice animation. It should be a scroll to bottom and not to top. The last item of the page is a submit button with #submit: <input type="submit" class="submit" id="submit" name="submit" value="Ok, Done."> The animation should not be too fast and should be

How can I select an element with multiple classes?

by 5:22:00 AM
undefined
How can I select an element with multiple classes? I want to select all the elements that have the two classes a and b. <element class="a b"> So, only the elements that have both classes. When I use $(".a, .b") it gives me the union, but I want the intersection. Answer: If you want an intersection, just write the selectors together without spaces in between. $('.a.b') So for an element that has an ID of a with classes b and c, you would write: $('#a.b.c') http://stackoverflow.com/questions/1041344/how-can-i-select-an-element-with-multiple-classes

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