Reputation: 1038
I have a <textarea>
defined like this:
<textarea class="form-control notetext" id="{{this._id}}-notetext" name="notetext">{{this.text}}</textarea>
I use ajax to send data and load a partial webpage.
Then I try to find the <textarea>
and list the results to the console.
The problem is that elements[0]
is returning undefined
in Internet Explorer 11 (haven't tried any other versions), but works fine in Chrome and Firefox. I have tried 3 variations which all give the same result. Is there a solution?
$.get('/page/' + Id + '/partial/', function(res) {
$('#sectional').html(res);
//variation 1
var elements = document.getElementsByClassName('notetext');
//variation 2
var elements = document.querySelectorAll('.notetext');
//variation 3
var elements = document.getElementsByTagName("textarea");
});
Also, please note that id
is dynamically created, so I can't .getElementById
(which would only return 1 result instead of an array). I saw a post somewhere that had a method to use regex on .getElementById
, but it returned null as well.
Upvotes: 1
Views: 60
Reputation: 1038
...and it turned out that it was working in IE11 after all. I was originally using getElementsbyName
which doesn't work properly in IE11 (it gets ID instead). So I changed it to the variations listed above, which all gave the same incorrect result. But after I quit and restarted the browser, the code worked fine. I'm not sure if I can change a setting somewhere in IE so this doesn't happen again?
Upvotes: 1