¿Qué es jQuery para Document.createElementNS ()?
¿Qué es jQuery para Document.createElementNS ()?
function emleGraphicToSvg(aGraphicNode) {
var lu = function luf(aPrefix){
switch (aPrefix){
case 'xhtml': return 'http://www.w3.org/1999/xhtml';
case 'math': return 'http://www.w3.org/1998/Math/MathML';
case 'svg': return 'http://www.w3.org/2000/svg';
}
return '';
};
var svg = document.evaluate("svg:svg",
aGraphicNode, lu, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
singleNodeValue;
$(svg).children().remove();
rect = document.createElementNS(lu('svg'), "rect");
rect.setAttribute("x", "35");
rect.setAttribute("y", "25");
rect.setAttribute("width", "200");
rect.setAttribute("height", "50");
rect.setAttribute("class", "emleGraphicOutline");
svg.appendChild(rect);
}
El código es un fragmento simplificado deEmle - Equipo de laboratorio de matemática electrónica Archivo JavaScriptemle_lab.js.
La función de búsqueda,luf()
, asigna una referencia completa a un nombre abreviado para el espacio de nombres en la cadena XPath ycreateElementNS()
. La existenciasvg:svg
está ubicado, eliminado y reemplazado por un nuevo rectángulo.