javascript - addEventListener working in firefox but not in chrome -
javascript - addEventListener working in firefox but not in chrome -
the given code works in mozilla firefox 31.0 not in google chrome 38.0.2125.104 how can issue solved?
please note : using change() function or jquery not alternative here!
<body> <select id="category"> <option value="movies">movies</option> <option value="artist">artists</option> <option value="authors">authors</option> <option value="chemistry">chemistry</option> </select> </body> <script> window.onload = initialise; function initialise() { var options = document.getelementsbytagname('option'); (var = 0; < options.length; i++) { options[i].addeventlistener("click", getquestion, false); //console.log(i); } } function getquestion() { console.log("getting question.."); } </script> </html>
i don't know why aren't binding aren't on alter function? can bind once?
//untested var category = document.getelementsbyid('category'); category.addeventlistener("change", getquestion, false);
also, if you're not against jquery, might want it gets rid of cross-browser issues. in jquery:
$('body').on('change', '#category', function() { getquestion($(this)); })
javascript google-chrome cross-browser
Comments
Post a Comment