I am working with addeventlistener
to create events and dynamically adding removing class name too. This is my code. Am getting expected result for first text box but not the next where i am wrong.
<html>
<style>
.test5 {
border: 1px solid #000;
outline: none;
}
</style>
<body>
<form id="form">
<input type="text" id="ids" class="test1" value="test1">
<div class="test7" id="test">test</div>
<input type="text" id="ids" class="test1" value="test2">
</form>
<script>
function gettext() {
var val = this.className += " test5";
console.log(val);
}
function gettexts() {
var val1 = document.getElementById('ids').classList.remove('test5');
}
var get = document.getElementsByClassName('test1');
//for (i = 0; i < get.length; i++) {
//get[i].addEventListener('focus', gettext, false);
//get[i].addEventListener('blur', gettexts, false);
get[0].addEventListener('focus', gettext, false);
get[0].addEventListener('blur', gettexts, false);
//}
</script>
</body>
<html>