I use jQuery a lot, especially the find
method which is why this little quirk threw me. I've thought of find
to be an extension to a selector string. It allows some use of
arbitrary methods after the selector string and then continues to find
even more. But using it with a finite selector (:first, :last, :eq, etc)
causes it to search within each element. This isn't a problem for
classes or elements within the selection, as find will return any number
of those. But using it to retrieve the first element in the set, causes
it to return the first element in each currently selected element.
The first line retrieves the last list item, Blue. The
second line retrieves the last list item in each ordered list,
as does the third line. The fourth line is what is necessary to match
the same element as the selector string in line one, albeit with a gap
for the aforementioned extra methods. Is there a simpler way of
I know the current functionality of find has been like this
since 1.6 at least, so it might just break something if it changed.
But I would prefer it if the each method would act as
find does currently, and then find would act as a
continuation of the selector string.
I've been toying with inheritance and the one thing I cannot seem to grasp is how exactly jQuery managed to wrap an array of elements with methods from an object. Everything I've tried just fails pitifully. I think this is maybe my closest demonstration, but as you can see it isn't inheriting the methods, but copying them which is not what I wanted. Any help would be appreciated, or a pointer to somewhere that can help, but a demo would be even better.
Add an extra boolean parameter that will return the value of the removed attribute, instead of the element. So "removeAttr('foo', true)" would instead return "bar" as opposed to the jQuery object to chain. Would be useful instead of needing to store the selected element in a variable, only to call it again as one cannot remove the attribute and return its value in one line.
The same notation can be used for the removeData and removeProp methods, also if there are more than one element it will only return the value of the first selected, to keep with standard seen in the attr, data and prop methods.
Would anyone else find this usefull? I almost always use it in any project.
The 5th definition listed in the .attr() page: `$(elem).attr("checked") (1.6.1+) "checked" (String) Will change with checkbox state` is incorrect as that doesn't change, it reads the attribute from the DOM. Making something like this possible: http://jsfiddle.net/zWvpT/
The definition states the changed behaviour with version 1.6.1+ which is when .prop() first came to the scene, but if you change jQuery on jsfiddle to 1.8.3 it will still behave like prop. It isn't until 1.9.x that .attr() became possible to return the actual (unchanged) attribute of the element, which you can also check on jsfiddle. I guess someone forgot to update the documentation.
I don't know if it's just me being incompetent, however using a $.get requests within $.when returns different results than only using $.get but only when there is another promise being returned from an animation. I've tried to illustrate my problem as clearly as possible but I've never used jsbin before either, so fingers crossed.
All the $.when XHR requests returns the document HTML but it's inconsistent with regards to tables. I initially thought there was something wrong with the $.when as I've never used that before either, but a simple switch to $.get resolved the issue, upon further testing it is only apparent (to me) to effect tables which seems rather odd.
Can anyone can tell me what I'm doing wrong, or if it is indeed a bug, thanks.