All In One Script
MENU

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

How do I format a Microsoft JSON date?

by 5:18:00 AM
undefined
How do I format a Microsoft JSON date? I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this: /Date(1224043200000)/ From someone totally new to JSON - How do I format this to a short date format? Should this be handled somewhere in the jQuery code? I've tried the jQuery.UI.datepicker plugin using $.datepicker.formatDate() without any success. FYI: Here's the solution I

How do I detect a click outside an element?

by 5:17:00 AM
undefined
How do I detect a click outside an element? I have some HTML menus, which I show completely when a user clicks on the head of these menus. I would like to hide these elements when the user clicks outside the menus' area. Is something like this possible with jQuery? $("#menuscontainer").clickOutsideThisElement(function() { // Hide the menus }); Answer: Attach a click event to the document body which closes the window. Attach a separate click event to the window which stops propagation to the

Get selected text from a drop-down list (select box) using jQuery

by 5:07:00 AM
undefined
Get selected text from a drop-down list (select box) using jQuery How can I get a drop-down list selected text in jQuery, not using the selected value? Answer: $("#yourdropdownid option:selected").text(); http://stackoverflow.com/questions/1643227/get-selected-text-from-a-drop-down-list-select-box-using-jquery

How can I refresh a page with jQuery?

by 5:06:00 AM
undefined
How can I refresh a page with jQuery? How can I refresh a page with jQuery? Answer: Use location.reload(): $('#something').click(function() { location.reload(); }); The reload() function takes an optional parameter that can be set to true to force a reload from the server rather than the cache. The parameter defaults to false, so by default the page may reload from the browser's cache. http://stackoverflow.com/questions/5404839/how-can-i-refresh-a-page-with-jquery

.prop() vs .attr()

by 5:05:00 AM
undefined
.prop() vs .attr() So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style'); }) or in this case do they do the same thing? And if I do have to switch to using prop(), all the old attr() calls will break if i switch to 1.6? UPDATE selector = '#id' $(selector).click(function() { //instead of: var getAtt = this.getAttribute('style'); //do i use: var thisProp = $(this).prop('style'); //or: var thisAttr = $(this).attr('style'); console.log(getAtt, thisProp, thisAttr); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> <div id='id' style="color: red;background: orange;">test</div> (see also

Instagram