jQuery to JavaScript code -


i want convert below jquery code pure javascript load javascript function.

html

<select name="select" id="select" >     <option id="en" value="global.html">global</option>     <option id="au" value="australia.html">australia</option>     <option id="id" value="indonesia.html">indonesia</option> </select> 

js code:

function getcode () {     var = new date().gettime();     var randomnumber = math.floor((math.random() * 100) + 1);     var uniquenumber = + 'a' + randomnumber;     $.getscript("getcountrycode.js?" + uniquenumber, function(data, textstatus, jqxhr) {         if (country){            var code = country;            alert("country code:" + code);            document.getelementbyid(code).selected = 'selected';            document.getelementbyid('select').onchange.apply();          }     }); } 

want add below code in pure javascript format fix issue.

$('.selector #select option[id='+code+']').attr('selected', 'selected'); $('.selecto #select').trigger('change'); 

you try code:

edited:

document.getelementbyid(code).selected = 'selected'; document.getelementbyid('select').onchange.apply(); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -