I am writing a chrome extentions whihc determines the clicked elements xpath dynamically. It creates a text area web element with insertAdjacentHTML function (like following) and the clicked elements xpath is placed to it.
document.body.insertAdjacentHTML('beforeend',this.html);
//this.html is string version of text area web element
document.addEventListener('click', this.getData, true);
The above code gets the xpath of the element and places it to the created text area. I also want to calculate and show the number of elements that matched with the xpath in the text area(user can edit the text area) To do that I am trying to add another eventlistener for the text area element which is like following:
var element= document.getElementById("inspector-text-area")
element.addEventListener('change',function(e){
console.log("event fired")
...
});
after running the extention, the xpath of the clicked element is placed to created text area web element but when I edit the text area the next added event listener's function is not fired. What is wrong I do? Thanks..
element.addEventListener('change',function(e){inspector-text-areaactually on the page when you callgetElementById("inspector-text-area")? 2. When do you expect the event to fire? Thechangeevent only fires when the field value is updated, which usually happens when the field loses focus -- not as the user is typing. If you want to see changes as the user types consider usingkeyupevent instead.document.addEventListener('click', this.getData, true);it worked. By the way @ChrisCamaratta the type of the event that I want is 'keyup' event. Thank for this information