Ie11 And Queryselector Issue
I got on my page inside a DIV with content editable on some text. In this text I need to get the value of all P elements (text written by user) but I need to exclude all span eleme
Solution 1:
You stated that the document mode is 5
.
This means that IE is running in Quirks Mode. This mode is designed to emulate IE5, and as a result it disables most of the browser features invented since IE5, including querySelector
.
You can resolve the problem by preventing the browser from going into Quirks Mode.
This is achieved by making sure (1) that your HTML is valid, and (2) that it has a valid doctype declaration as the first line. If you don't have a doctype, add the following to the top of your code:
<!DOCTYPE html>
Solution 2:
Why not something like
var spans = textRecup.querySelectorAll("span");
for (var i=0;i<span.length;i++) {
spans[i].parentNode.removeChild(spans[i]);
}
window.onload = function() {
document.getElementById("get").onclick = function() {
var div = document.getElementById("cnt");
var spans = div.querySelectorAll("span");
for (var i = 0; i < spans.length; i++) {
spans[i].parentNode.removeChild(spans[i]);
}
console.log(div.innerHTML);
}
}
<divid="cnt"contenteditable><p>Here is some text and a <span>span</span> more text<br/>
Here is some text and a <span>span</span> more text<br/>
Here is some text and a <span>span</span> more text<br/>
Here is some text and a <span>span</span> more text<br/></p></div><inputtype="button"id="get"value="get" />
Output in IE10 AND IE11 AND EDGE
Post a Comment for "Ie11 And Queryselector Issue"