Answer the question
In order to leave comments, you need to log in
How to trigger an event on an element from javascript?
There is a checkbox on it, a function hangs on the onchange event.
When the checkbox state changes from the script through .attr("checked","checked"), the event does not fire.
Tell me how to change the element so that the event fires, or how to forcefully report that the element has changed.
Answer the question
In order to leave comments, you need to log in
There are such pebbles underwater
1. $(element).click();
- The checkbox will change the state in all browsers, but the change event will not work in Opera, which in other browsers fires after click ... distinguished himself... but I don't remember exactly... ) In my case, $(element).click().change() satisfied if I didn't worry about double triggers. If the change event is not important... $(element).click(); is sufficient.
3.After changing the checkbox dynamically, it becomes unexpectedly difficult in js to check whether it is 1 or 0 turned out ... When checking the attr('checked') attribute or the checked property of a DOM object, they give different results in some browsers. If you check during the click, it is likely that there is a discrepancy due to the fact that some browsers change the state of the checkbox before the click, others after the click. If you check the state of the checkbox in the click handler, then you can stumble upon different results in different browsers, but this is just a suspicion ... since all the glitches have disappeared using the jquery selector value=$(element).is(':checked'); which is what I recommend :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question