Kevin Old schrieb:
> Hello everyone,
>
> I'm having trouble getting started with a simple piece of code (I'm
> sure) but for some reason since I'm dealing with radio buttons it
> seems hard.
>
> What I need to do is "toggle" a div based on whatever radio button is
> checked, Lease or Sale.
> I basically want to put a show() for the div when Lease is clicked on
> and a hide() on Sale when it is clicked on, not hard, but I don't know
> how to do it with one click event.
>
> Since I'm dealing with two separate elements, do I need two click events?
>
> Going with that in mind, I put this together:
> http://kold.homelinux.com/radiotest.html
>
> Just wondering if anyone has any tweaks that might make the code a
> little tighter as I plan on having about 20+ radio button sets and
> that could turn into a lot of code and click events.
>
You could try to add the event handler to a sourrounding form, eg:
<form id="clickhandler">
<radio value="sale" />
<radio value="lease" />
</form>
$('#clickhandler').click( function(event) {
var t = event.target;
if(t.type && t.type == "radio") {
var extra = $('#extra');
if(t.value == "lease") {
extra.show();
} else {
extra.hide();
}
}
});
That should give you the idea of event delegation. Make sure to use a
"late" revision of jQuery where the event's target object is fixed.
1.0.3 contains the fix but has other event-fix related bugs.
--
Jörn Zaefferer
http://bassistance.de
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/