Omair .
Omair .

Reputation: 344

Delete a child node

I am trying to delete the string attribute here, but I guess I don't have reference to the child node. How should this work?

<!DOCTYPE HTML>
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
    <script type="text/javascript">
        var attrs = document.getElementById('test-1');
        attrs.removeAttribute('string');
    </script>
    <mask>
        <mpath>
            <font-face-format string="" id="test-1"></font-face-format>
       </mpath>  
    </mask>
</svg>

Upvotes: 0

Views: 300

Answers (2)

You are trying to reference it when it still doesn't exist.

try moving your script block to the end of the document like

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">    
    <mask>
        <mpath>
            <font-face-format string="" id="test-1"></font-face-format>
        </mpath>  
    </mask>
    <script type="text/ecmascript">
       var attrs = document.getElementById('test-1');
       attrs.removeAttribute('string');
    </script>
</svg>

Upvotes: 2

dku.rajkumar
dku.rajkumar

Reputation: 18578

make use of window.onload so that the code will executed once the element is created. try this

<script type="text/javascript">
  window.onload = function(){
        var attrs = document.getElementById('test-1');
        attrs.removeAttribute('string');
 };
</script>

Upvotes: 2

Related Questions