stevenfrog (3) [Avatar] Offline
#1
I'm reading chapter 8, and have a question about "remove event.target":

In chapter8/bootcloset/phase.1.html, and phase.2.html, you always call:
$('[value=""]',event.target).remove();

$("'[value=""]'").remove() is to remove the selector "--choose XXX--", but why "$(event.target).remove()"?
The event.target in this page is the selector with the its value?
I still do not know why you do that.
If I remove it, no affect to result.

Please explain your reason.
bear.bibeault (675) [Avatar] Offline
#2
Re: Why remove event.target
In this case event.target is the select element that was triggered. By passing it to the jQuery method as the second parameter, it limits the search context to only that select and its descendants. That way, only the "choose" option element of that one select element can be removed, rather than all such elements on the entire page.
stevenfrog (3) [Avatar] Offline
#3
Re: Why remove event.target
As your means, the code should be:
$('[value=""]' event.target).remove();

Please note: "'[value=""]' event.target" between two parameters, there is no comma.
bear.bibeault (675) [Avatar] Offline
#4
Re: Why remove event.target
No, the comma is necessary to separate the first from the second parameter in the method call.
stevenfrog (3) [Avatar] Offline
#5
Re: Why remove event.target
I checked the book again, you'are right.

This comma means second parameter, it limit the rang.

Thanks!
bear.bibeault (675) [Avatar] Offline
#6
Re: Why remove event.target
My pleasure!