Odczyt atrybutów elementu w obsłudze zdarzena w javascript

<select name="banner_url" onchange="var idx=this.selectedIndex;
var value=this.options[idx].getAttribute('banner_url');
var element = document.getElementById('img_banner_url');
element.setAttribute('src', value); element.style.display='block'">


!{section name=ii loop=$data}!
    !{capture assign=banner_url}!http://kody.wig.pl/!{/capture}!
    <option value="!{$banner_url}!" banner_url="!{$banner_url}!">
    !{$data[ii].name}! ---> !{$banner_url}!</option>
!{/section}!

</select>
<br><br>

<img src="" id="img_banner_url" style="display:none">

Dodanie atrybutu do diva


var div = document.createElement('div');
div.className = "box";
div.id='test';
div.innerHTML = '[<a href="http://mapy.emiejsca.pl/niedrzwica_duza_niedrzwica_duza_lubelski_lubelskie,mapa.html">Niedrzwica Duża</a>]';
div.setAttribute('index', 100);

Utworzenie najprostszego dokumentu XML

$docs = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$pages = $docs->appendChild(new DOMElement('pages'));
$element_page = $pages->appendChild(new DOMElement('page'));
$element_page->setAttribute("id", "123456");
$element_name = $docs->createElement('link', 'link numer 123456');
$element_page->appendChild($element_name);
$element_CDATA = $docs->createCDATASection('http://kody.wig.pl/');
$element_url = $element_page->appendChild(new DOMElement('url'));
$element_url->appendChild($element_CDATA);
$xmldata = $docs->saveXML();
echo $xmldata;

Dodawanie dynamiczne tabeli do komórki innej tabeli


<p class="mce_ws_kod">&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt; New Document &lt;/TITLE&gt;
&lt;META NAME="Author" CONTENT=""&gt;
&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- 
 function ukryjtab(id) {

<p class="mce_ws_kod">  var element = document.getElementById(id);
   while (element.firstChild) {
    element.removeChild(element.firstChild);
   }
 }
<p class="mce_ws_kod">    function dodajtab(id) {</p>

<p class="mce_ws_kod">        var element = document.getElementById(id);
        var tbl     = document.createElement("table");
        var tblBody = document.createElement("tbody");

<p class="mce_ws_kod">        for (var j = 0; j &lt; 2; j++) {
            var row = document.createElement("tr");
            for (var i = 0; i &lt; 2; i++) {

<p class="mce_ws_kod">                var cell = document.createElement("td");
                var cellText = document.createTextNode("komórka nr: "+j+", kolumna nr: "+i);
                cell.appendChild(cellText);
                row.appendChild(cell);
            }
            tblBody.appendChild(row);
        }

<p class="mce_ws_kod">        tbl.appendChild(tblBody);
        element.appendChild(tbl);
        tbl.setAttribute("border", "1");
    }
//--&gt;
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;

<p class="mce_ws_kod">&lt;BODY&gt;
&lt;TABLE border="1"&gt;
&lt;TR&gt;
 &lt;TD&gt;fiat stilo&lt;/TD&gt;
 &lt;TD&gt;1,6&lt;/TD&gt;
 &lt;TD&gt;&lt;input type="button" name="wybor" value="pokaz" onClick="dodajtab(2)"&gt;&lt;input type="button" name="wybor" value="ukryj" onClick="ukryjtab(2)"&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
 &lt;TD colspan="3" id="2"&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
 &lt;TD&gt;fiat panda&lt;/TD&gt;
 &lt;TD&gt;1,1&lt;/TD&gt;
 &lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;