How to show loading spinner in jQuery?

There are a couple of ways. My preferred way is to attach a function to the ajaxStart/Stop events on the element itself. $(‘#loadingDiv’) .hide() // Hide it initially .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ; The ajaxStart/Stop functions will fire whenever you do any Ajax calls. Update: As of jQuery 1.8, the documentation … Read more

Change the image source on rollover using jQuery

To set up on ready: $(function() { $(“img”) .mouseover(function() { var src = $(this).attr(“src”).match(/[^\.]+/) + “over.gif”; $(this).attr(“src”, src); }) .mouseout(function() { var src = $(this).attr(“src”).replace(“over.gif”, “.gif”); $(this).attr(“src”, src); }); }); For those that use url image sources: $(function() { $(“img”) .mouseover(function() { var src = $(this).attr(“src”); var regex = /_normal.svg/gi; src = this.src.replace(regex,’_rollover.svg’); $(this).attr(“src”, src); … Read more

Clear form fields with jQuery

For jQuery 1.6+: $(‘:input’,’#myform’) .not(‘:button, :submit, :reset, :hidden’) .val(”) .prop(‘checked’, false) .prop(‘selected’, false); For jQuery < 1.6: $(‘:input’,’#myform’) .not(‘:button, :submit, :reset, :hidden’) .val(”) .removeAttr(‘checked’) .removeAttr(‘selected’); Please see this post: Resetting a multi-stage form with jQuery Or $(‘#myform’)[0].reset(); As jQuery suggests: To retrieve and change DOM properties such as the checked, selected, or disabled state of … Read more

jQuery get the rendered height of an element?

Try one of: var h = document.getElementById(‘someDiv’).clientHeight; var h = document.getElementById(‘someDiv’).offsetHeight; var h = document.getElementById(‘someDiv’).scrollHeight; clientHeight includes the height and vertical padding. offsetHeight includes the height, vertical padding, and vertical borders. scrollHeight includes the height of the contained document (would be greater than just height in case of scrolling), vertical padding, and vertical borders.

Disable button in jQuery

Use .prop instead (and clean up your selector string): function disable(i){ $(“#rbutton_”+i).prop(“disabled”,true); } generated HTML: <button id=”rbutton_1″ onclick=”disable(1)”>Click me</button> <!– wrap your onclick in quotes –> But the “best practices” approach is to use JavaScript event binding and this instead: $(‘.rbutton’).on(‘click’,function() { $(this).prop(“disabled”,true); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”></script> <button class=”rbutton”>Click me</button> http://jsfiddle.net/mblase75/2Nfu4/

Downloading jQuery UI CSS from Google’s CDN

The Google AJAX Libraries API, which includes jQuery UI (currently v1.10.3), also includes popular themes as per the jQuery UI blog: Google Ajax Libraries API (CDN) Uncompressed: http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js Compressed: http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js Themes Uncompressed: black-tie, blitzer, cupertino, dark-hive, dot-luv, eggplant, excite-bike, flick, hot-sneaks, humanity, le-frog, mint-choc, overcast,pepper-grinder, redmond, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, and … Read more

How to wait 5 seconds with jQuery?

Built in javascript setTimeout. setTimeout( function() { //do something special }, 5000); UPDATE: you want to wait since when the page has finished loading, so put that code inside your $(document).ready(…); script. UPDATE 2: jquery 1.4.0 introduced the .delay method. Check it out. Note that .delay only works with the jQuery effects queues.

How to change color of SVG image using CSS (jQuery SVG image replacement)?

Firstly, use an IMG tag in your HTML to embed an SVG graphic. I used Adobe Illustrator to make the graphic. <img id=”facebook-logo” class=”svg social-link” src=”https://stackoverflow.com/images/logo-facebook.svg”/> This is just like how you’d embed a normal image. Note that you need to set the IMG to have a class of svg. The ‘social-link’ class is just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)