Wednesday, November 23, 2011

jQuery 1.7 disabled selector update

I just reacently uppdated the current project to jQuery 1.7. The main reason for this was to get rid of the "event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future." error, but when running my Jasmine tests I encountered one small but important difference in the new versions way of using selectors with the disabled keyword.
Up to jQuery version 1.6.4 you could write a selector to get all elements that where not disabled like this:
$('#someId input[disabled=false]')
That selector would return a list of all input elements that where not disabled. If you do the same in jQuery version 1.7 you will get an empty array as a result. This corresponds more with how the HTML spec is defined the keyword ether is there or not, it has no other values attached to it. Many browsers have, and still support the erroneous syntax of disabled="disabled" or some times disabled="true".


Another way of doing the same selection, one that is more correct and works in both older and the new 1.7 version is:
$('#someId input:not(disabled)')
This is the preffered and correct way of doing the selection if you still want to get all the elements that are not disabled.