Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  197] [ 4]  / answers: 1 / hits: 27878  / 11 Years ago, wed, october 30, 2013, 12:00:00

I want to trigger change event and check checkbox from javaScript not jQuery.

I am having issues with jQuery because of this Strange Behaviour.


What i used to do with jQuery is:



$('#laneFilter').prop('checked','true').trigger('change');


I want same to do with javaScript. This must be really simple but i could not find the way .
please help thanks in advance


More From » checkbox

 Answers
6

There's a couple of ways you can do this. The easiest method is to just call that function:



var Chkinput = document.getElementById(laneFilter);
Chkinput .onchange();


If you need it to simulate the real event in full, or if you set the event via the html attribute or addEventListener/attachEvent, you need to do a bit of feature detection to correctly fire the event:



if (createEvent in document) {
var evt = document.createEvent(HTMLEvents);
evt.initEvent(change, false, true);
element.dispatchEvent(evt);
}

[#74619] Tuesday, October 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanajamiep

Total Points: 466
Total Questions: 113
Total Answers: 108

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
susanajamiep questions
Sun, Jun 12, 22, 00:00, 2 Years ago
Mon, Mar 7, 22, 00:00, 2 Years ago
Wed, Jun 10, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;