[jQuery] How to customize already existing events?
Hello,
Let's say I have the folowing code I can't change (it's not mine) :
<select name="myselect"
onchange="this.nextSibling.visibility='hidden';">
<option value="1">One</option>
<option value="2">Two</option>
</select>
How can I put my own "change" event handler, but being able to run
the original one as well?
I tried that :
$(document).ready(function() {
var currentOption = $('select[@name= myselect] > option
[@selected]').attr('value');
var currentOnChange = $('select[@name=myselect]').attr('onchange');
currentOnChange = currentOnChange.replace('/this/', '$(\'select
[@name=myselect]\')');
$('select[@name= myselect]').removeAttr('onchange');
$('select[@name= myselect]').bind('change', function(event) {
if (confirm('Are you sure?')) {
eval(currentOnChange);
} else {
$('select[@name= myselect] > option[@selected]').removeAttr
('selected');
$('select[@name= myselect] > option[@value='+currentOption
+']').attr('selected', 'selected');
}
});
});
The eval doesn't seem to do anything. Any idea how to do this?
On a side note, I noticed that I had to use removeAttr() instead of
unbind(), which was not doing anything.
-Nicolas
--
Nicolas "Brush" HOIZEY
Clever Age : http://www.clever-age.com/
Gastero Prod : http://www.gasteroprod.com/
Photos : http://www.flickr.com/gp/38608514@N00/M1c002
phpHeaven : http://www.phpheaven.net/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/