JavaScript Reference/Javascript Methods/setAttributeNode

Материал из Web эксперт
Перейти к: навигация, поиск

"setAttributeNode()" Example

    
<html>
<body>
<script language="JavaScript">
function function1() {
    var newAttr = document.createAttribute("width");
    newAttr.nodeValue = "400px"
    document.getElementById("myB").setAttributeNode(newAttr); 
} 
</script>
<table id="myB" border=3 cellpadding="5" style="border-color:blue">
    <tr>
        <th>Expand this table</th>
        <th>This is another cell</th>
    <tr>
</table>
<input id="myB" type="button" value="Add attribute to the table" onclick="function1();">
</body>
</html>



"setAttributeNode()" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<a>                             <acronym>                     |
|                |<address>                       <applet>                      |
|                |<area>                          <b>                           |
|                |<base>                          <basefont>                    |
|                |<bdo>                           <bgsound>                     |
|                |<big>                           <blockquote>                  |
|                |<body>                          <br>                          |
|                |<button>                        <caption>                     |
|                |<center>                        <cite>                        |
|                |<code>                          <col>                         |
|                |<colgroup>                      <comment>                     |
|                |<custom>                        <dd>                          |
|                |<del>                           <dfn>                         |
|                |<dir>                           <div>                         |
|                |<dl>                            <dt>                          |
|                |<em>                            <embed>                       |
|                |<fieldset>                      <font>                        |
|                |<form>                          <frame>                       |
|                |<frameset>                      <head>                        |
|                |<hn>                            <hr>                          |
|                |<html>                          <i>                           |
|                |<iframe>                        <img>                         |
|                |<input>                         <input type="button">         |
|                |<input type="checkbox">         <input type="file">           |
|                |<input type="hidden">           <input type="image">          |
|                |<input type="password">         <input type="radio">          |
|                |<input type="reset">            <input type="submit">         |
|                |<input type="text">             <ins>                         |
|                |<isindex>                       <kbd>                         |
|                |<label>                         <legend>                      |
|                |<li>                            <link>                        |
|                |<listing>                       <map>                         |
|                |<marquee>                       <menu>                        |
|                |<meta>                          <nobr>                        |
|                |<noframes>                      <noscript>                    |
|                |<object>                        <ol>                          |
|                |<optgroup>                      <option>                      |
|                |<p>                             <param>                       |
|                |<plaintext>                     <pre>                         |
|                |<q>                             <rt>                          |
|                |<ruby>                          <s>                           |
|                |<samp>                          <script>                      |
|                |<select>                        <small>                       |
|                |<span>                          <strike>                      |
|                |<strong>                        <style>                       |
|                |style                           <sub>                         |
|                |<sup>                           <table>                       |
|                |<tbody>                         <td>                          |
|                |<textarea>                      <tfoot>                       |
|                |<th>                            <thead>                       |
|                |<title>                         <tr>                          |
|                |<tt>                            <u>                           |
|                |<ul>                            <var>                         |
|                |<wbr>                           <xml>                         |
|                |<xmp>                                                         |
+----------------+--------------------------------------------------------------+



"setAttributeNode()" Syntax, Parameters and Note

Note:
This method adds an attribute node to the element.
    
Syntax:
    
document.getElementById("elementID").setAttributeNode(param1)
document.all.elementID.setAttributeNode(param1) // IE only
Parameters:
    param1   Required; the name of the attribute to be added.