Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- Date: Fri, 17 Dec 2010 09:32:40 +0900
- From: Darren Cook <darren@example.com>
- Subject: Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- References: <4D08CDD3.5020806@example.com> <AANLkTim1yQZmd+=2WBW3bZeFmggTwWP8u-bUaVjaaEB1@example.com> <AANLkTimPCwJv-dPvsB12f37D5-yOpsV636evESRWTK_v@example.com> <4D08FD73.9020605@example.com> <AANLkTin4HmBymz=+-C+ZHS+CRXR+-u5K5Cpt5usTZOAc@example.com> <4D0A2786.80301@example.com>
- User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
> In any case, going with your code as a model, basically meticulously > building the tree of nested divs with Javascript constructors, and then > using appendChild to connect them all together, does result in the HTML > getting concatenated together in the expected order. > > It's a little tedious, but it works, and that's what's important. Does it work in all browsers? The rule of thumb for cross-browser development: always use jquery. The rule of thumb for painless web development: always use jquery. With JQuery your original code works exactly how you expected, and will work in all browsers: <div id="test"></div> <script> $('<div id="1"><div id="2"><div id="3"></div></div></div>').appendTo('#test'); </script> Here is a slightly expanded example to show it is indeed creating nested divs: <div id="test"></div> <script> $('<div id="1">111<div id="2">222<div id="3">333</div>-222</div>-111</div>').appendTo('#test'); $('#3').click(function(){alert("Merry Christmas!")}); $('#2').click(function(){alert("Happy New Year!")}); </script> (Tested in firefox 3.6 and Chromium 8; if it is not working in IE6/7/8 let me know as I have to dust off the windows machine later today anyway.) Darren P.S. appendTo() puts it after the last child of the given id. I.e. it adds a child. prependTo() makes it first child. Use insertBefore() and insertAfter() to make a sibling of the given id, instead of a child. -- Darren Cook, Software Researcher/Developer http://dcook.org/gobet/ (Shodan Go Bet - who will win?) http://dcook.org/work/ (About me and my work) http://dcook.org/blogs.html (My blogs and articles)
- Follow-Ups:
- References:
- [tlug] Javascript and I have different ideas about what "concatenate" means.
- From: Dave M G
- Re: [tlug] Javascript and I have different ideas about what "concatenate" means.
- From: David Shanahan
- Re: [tlug] Javascript and I have different ideas about what "concatenate" means.
- From: Ruben Dorado
- Re: [tlug] Javascript and I have different ideas about what "concatenate" means.
- From: Dave M G
- Re: [tlug] Javascript and I have different ideas about what "concatenate" means.
- From: Marco Toldo
- Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- From: Dave M G
Home | Main Index | Thread Index
- Prev by Date: [tlug] Japan
- Next by Date: Re: [tlug] Wireless digital photo frames
- Previous by thread: Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- Next by thread: Re: [tlug] Javascript and I have different ideas about what "concatenate" means. [SOLVED]
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links