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

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -