Edit #2: The problem does not exist anymore. It was some kind of scoping problem. But now it's working.I am really sorry for the inconvenience.
In some part of my script there's an event delegation and specifying target by id. But when i run it. the line if(evt.target.id == ("subtaskSubmit" + subtaskCounter))
seems not to work at all. Here's my code :
var subtaskCounter = 0;
aWholeTask.addEventListener("click", function(evt){
//other event targets specifications ..
if(evt.target.id == "divide"){
var subtaskInput = document.createElement("input"),
subtaskSubmit = document.createElements.button("submit"), // this is a special function i've made, don't bother about it. I've used it all over the place and it's working normally.
subtaskContainer = document.createElement("p");
subtaskContainer.style.marginLeft = "40px";
subtaskInput.id = "subtaskInput" + (++subtaskCounter);
subtaskInput.type = "text";
subtaskSubmit.id = "subtaskSubmit" + subtaskCounter;
subtaskContainer.appendChildren(subtaskInput,subtaskSubmit);
aWholeTask.appendChild(subtaskContainer);
}
if(evt.target.id == ("subtaskSubmit" + subtaskCounter)){
//this event is the one that not working when i press on that element
alert("hello");
}
});
Edit: I've made some changes to debug the code and the result is strange :
var subtaskCounter = 0;
aWholeTask.addEventListener("click", function(evt){
//other event targets specifications ..
if(evt.target.id == "divide"){
var subtaskInput = document.createElement("input"),
subtaskSubmit = document.createElements.button("submit"), // this is a special function i've made, don't bother about it. I've used it all over the place and it's working normally.
subtaskContainer = document.createElement("p");
subtaskContainer.style.marginLeft = "40px";
subtaskInput.id = "subtaskInput" + (++subtaskCounter);
subtaskInput.type = "text";
subtaskSubmit.id = "subtaskSubmit" + subtaskCounter;
subtaskContainer.appendChildren(subtaskInput,subtaskSubmit);
aWholeTask.appendChild(subtaskContainer);
}
if(evt.target.innerHTML == "Submit"){
alert(evt.target.id == ("subtaskSubmit" + subtaskCounter));
//And this surprisingly returns false !
}
});
So why does evt.target.id == ("subtaskSubmit" + subtaskCounter)
returns false
?