Actually I was needing this for handling "option" elements with a more simple way, more simple regexp. Cos of ie doesn't not append if use innerHTML = append content for select elements. Append operation is mentioned at links below, but does not work for option elements. And than I find a solution for this problem. If append content is option or options than use handleOptionElements, if not use asyncInnerHTML.
function append(el, child) {
if (child.nodeType === 1 || child.nodeType === 3) {
// Without clone, removes element if it is copied from document
return el.appendChild(child.cloneNode(true));
}
content = trim(content);
if (content.substring(0, 7) === "<option" &&
content.substring(content.length - 7) === "option>") {
handleOptionElements(content, el);
} else {
el.innerHTML = content;
}
return el;
}
http://james.padolsey.com/javascript/asynchronous-innerhtml/
Ways to increase performance when set big value to innerHTML
var re_standaloneAttributes = /^(select|disabl)ed$/i,
re_optionSearch = /<option\s*([^>]*)>(.*?)<\/option>/gi,
re_attributeSearch = /([^\s]*)=["'](.*?)["']|([\w\-]+)/g;
function handleOptionElements(content, targetElement) {
var options = [], attributes = [],
optionElement, optionElements = [], createOption;
(""+ content).replace(re_optionSearch, function(src1, attr, text) {
if (!src1) return;
(""+ attr).replace(re_attributeSearch, function(src2, name, value) {
if (!src2) return;
name = name || src2;
value = value || (value = re_standaloneAttributes.test(name) ? name : "");
attributes.push({name: name, value: value});
});
options.push({text: text || "", attributes: attributes});
// Reset attributes for each element
attributes = [];
});
createOption = (function() {
var option = document.createElement("option");
return function() { return option.cloneNode(true) };
})();
forEach(options, function(option) {
optionElement = createOption();
// optionElement.text doesn't work on ie 7-8
optionElement.textContent = optionElement.innerText = option.text;
forEach(option.attributes, function(attribute) {
optionElement.setAttribute(attribute.name, attribute.value);
});
if (targetElement !== undefined) {
targetElement.appendChild(optionElement);
} else {
optionElements.push(optionElement);
}
});
return optionElements;
}
document.querySelector("option[value='1'][data-foo='Foo'][readonly]").outerHTML?s.split(" ")? Just curious if it could work