What is jQuery for Document.createElementNS()?

后端 未结 2 491
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 11:04

What is jQuery for Document.createElementNS()?

function emleGraphicToSvg(aGraphicNode) {
  var lu = function luf(aPrefix){
    switch (aPrefix){
      case \         


        
相关标签:
2条回答
  • 2021-01-04 11:17

    What is jQuery for Document.createElementNS()?

    That would be:

    $(document.createElementNS('namespace', 'tag'))
    

    So in the OP's case:

    rect = $(document.createElementNS(lu('svg'), 'rect'))
        .addClass('emleGraphicOutline')
        .attr({
            x: 35,
            y: 25,
            width: 200,
            height: 50
        });
    

    But not much is really gained by using jQuery for that, of course. In any case, one can always wrap DOM nodes in jQuery with e.g. $(rect) after creating rect with vanilla JS.

    Note that jQuery has other issues with SVG, such as breaking viewBox due to lowercasing attributes, so plain JS must still be used for some attributes.

    0 讨论(0)
  • 2021-01-04 11:27

    For SVG, I have used Keith Wood's jquery.svg for some evaluation type projects.

    0 讨论(0)
提交回复
热议问题