New to jQuery, I don't quite understand some things (OK, a lot of things).
I have a bunch of <a>s within a <div id="myDiv"> and want to throw away the last one. My code is:
- try {
- $("#myDiv a").last().remove();
- } catch (e) {
- alert(e);
- }
I get an error saying that last() is not a function.
So, I change line 2 to:
$("#myDiv a:last").remove();I get no error but nothing was removed.
Checking out the forum, I then try this version of line 2:
$("#myDiv a :last-child").remove();And, that works.
But, that leaves some questions:
- I believe last() is a function relating to a wrapped set but why did I get that error?
- If :last doesn't want to return the last element of a wrapped set, what does it return? And why did remove() do diddly; was it passed an empty set so it took a break?
Thanks for anything that will help alleviate the confusion.