$ versus jQuery

Why would that be the case? Is his $/jQuery distinction correct? Because almost every JavaScript library defines a function called $. When you have many libraries in one document, conflicts may appear. If you are sure that jQuery is and always will be the only script defining that function, I wouldn’t have anything against using …

Read more

Ajax request with JQuery on page unload

I believe you need to make the request synchronous instead (it’s asynchronous by default) using the async : false parameter. Synchronous requests lock up the browser until they complete. If the request is asynchronous, the page just keeps on unloading. It’s quick enough that the request never even has time to fire off.

How to force a hover state with jQuery?

You will have to use a class, but don’t worry, it’s pretty simple. First we’ll assign your :hover rules to not only apply to physically-hovered links, but also to links that have the classname hovered. a:hover, a.hovered { color: #ccff00; } Next, when you click #btn, we’ll toggle the .hovered class on the #link. $(“#btn”).click(function() …

Read more

jQuery – disable selected options

Add this line to your change event handler $(“#theSelect option:selected”).attr(‘disabled’,’disabled’) .siblings().removeAttr(‘disabled’); This will disable the selected option, and enable any previously disabled options. EDIT: If you did not want to re-enable the previous ones, just remove this part of the line: .siblings().removeAttr(‘disabled’); EDIT: http://jsfiddle.net/pd5Nk/1/ To re-enable when you click remove, add this to your click …

Read more

How to add a function to jQuery?

Please see “Defining your own functions in jQuery” by Basil Goldman: In this post, I want to present how easy define your own functions in jQuery and using them. Modified, based on the code in the blog post linked above: jQuery.fn.yourFunctionName = function() { // `this` is the jQuery Object on which the yourFunctionName method …

Read more