SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    removeAttributeNode

    I don't know why this script worked.
    Code:
     
    <div id="top" align="center" > bbbbb </div>
    
    <button onclick="aa()">click me</button>
    
    <script type="text/javascript">
    
    function aa () {
    var d = document.getElementById("top"); 
    
    var d_align = d.getAttributeNode("align"); 
    
    d.removeAttributeNode(d_align); 
    }
    </script>

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean you don't know why it worked? It fails in IE. I assume you want to remove the attribute align? In that case, try this
    Code:
    function aa () {
    var d = document.getElementById("top"); 
    
    d.removeAttribute("align"); 
    }

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pepejeria;
    I found the above script in internet.
    Thanks for your reply. It worked very well.
    Code:
     
    <div id="top" align="center" > bbbbb </div>
    
    <button onclick="aa()">click me</button>
    
    <script type="text/javascript">
    
    
    function aa () {
    var d = document.getElementById("top"); 
    
    d.removeAttribute("align"); 
    alert(d.outerHTML) ;   // <DIV id=top > bbbbb </DIV>
    }
    </script>

    I found an example.
    http://www.w3schools.com/dom/tryit.a...eattributenode

    http://www.w3schools.com/dom/met_ele...ributenode.asp


    http://www.java2s.com/Code/JavaScrip...odeExample.htm
    Code:
      
    <html>
    <body>
    <script language="JavaScript">
    function function1(){
        var m = document.getElementById("myDiv").getAttributeNode("id");
        alert("The value of the attributeNode is: "+'"'+m.value+'"');
        var n = document.getElementById("myDiv").removeAttributeNode(m);
        alert("The attribute node has been removed");
    
    alert(document.getElementsByTagName('html')[0].innerHTML )
    }
    </script>
    <div id="myDiv">This is a div element</div>
    <input type="button" value="Get id attribute node value" onclick="function1();">
    </body>
    </html>
    <div id="myDiv">This is a div element</div>
    will be
    <div>This is a div element</div>
    ...
    Last edited by muazzez; Feb 5, 2007 at 16:35.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •