Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21421

Dom node creation?

From Tuxedo <tuxedo@mailinator.com>
Newsgroups comp.lang.javascript
Subject Dom node creation?
Date 2013-09-24 22:49 +0200
Organization albasani.net
Message-ID <l1sttn$gsi$1@news.albasani.net> (permalink)

Show all headers | View raw


Can someone advise me how to add dom nodes dynamically with javascript?

I'd like to add the elements as part of a function call via an onclick 
action, after a page has loaded, e.g.:
<a href=".." onclick="share_icons();">Share icons</a>.

These are the elements that need to appear onclick:

<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>

So it's a div with two classes, holding four <a> tags with classes and some 
'fb' and 'pi' stuff (facebook and pinterest) in two of them.

The div makes up various social content sharing buttons via addthis.com.

I guess the procedure would begin something like:

var div = document.createElement("div");
...

function share_icons(){
document.body.appendChild(div);
...

}

I'm a bit unfamiliar with the dom node creation syntax.

Many thanks for any pointers!

Tuxedo

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Dom node creation? Tuxedo <tuxedo@mailinator.com> - 2013-09-24 22:49 +0200
  Re: Dom node creation? Danny <dann90038@gmail.com> - 2013-09-24 15:17 -0700
    Re: Dom node creation? Tuxedo <tuxedo@mailinator.com> - 2013-09-25 00:51 +0200
      Re: Dom node creation? "J.R." <groups_jr-1@yahoo.com.br> - 2013-09-24 16:08 -0700

csiph-web