The page is here:
http://cistrome.org/cps/seqconfig?did=2693
And the original js codes are below(this one works well):
$(document).ready(function(){
$(".open_gene").on('change', function(event) {
$('#Gene_field').show();
});
$(".close_gene").on("change", function(event){
$("#Gene_field").hide();
});
});
So the .close_gene
has an event handler for change
. But when I want to trigger this event manually to hide the #Gene_field
, like this:
>>> $('.close_gene').trigger("change")
In FireBugs, the returned value is:
[input#nolimit_radio.close_gene all]
But the #Gene_field
is not hidden..
I was wondering that why I can't trigger change
event which should already bind
to function(event){ $("#Gene_field").hide();}
. Does anyone have ideas about this? Thanks!
var element = document. getElementById('just_an_example'); var event = new Event('change'); element. dispatchEvent(event); This will trigger event listeners regardless of whether they were registered by calling the addEventListener method or by setting the onchange property of the element.
Now, to detect when that radio box is changed, you can easily call the jQuery 'change' event inside your jQuery document ready function: $(document). ready(function(){ $('#my_radio_box'). change(function(){ alert('Radio Box has been changed!
$( "#foo" ). trigger( "click" ); As of jQuery 1.3, . trigger() ed events bubble up the DOM tree; an event handler can stop the bubbling by returning false from the handler or calling the .
Try this:
$(".close_gene").click();
Its working fine for me in Firebug Console... :)
Update:
This should also work, but will not change the state of radio button
$(document).ready(function(){
$(document).delegate(".open_gene",'change', function(event) {
$('#Gene_field').show();
});
$(document).delegate(".close_gene", "change", function(event){
$("#Gene_field").hide();
});
});
$('.close_gene').trigger("change");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With