jQuery-Append method create only element but not the id in the element

+1 Yannis Sp · September 10, 2014
I have an html code where i have some div tags:

<div class="results">
       <div id="r1" class="horizontal element">
           <img src="logo1.jpg" class="photo">
           <div id="1" class="data"></div>

And i have this jQuery code where i append more elements to the 
<div class="results"></div>
 when i click a button:

$(".results").append('<div id="r2" class="horizontal element"><img src="logo2.jpg" class="photo"><div id="2" class="data"></div></div>');});

The problem is that if i want to alert() the id of class="data" only the id="1" will show not the id="2" although the element was created(visible).

I have tried to re-arange the position of the jquery code but nothing happens.What am i doing wrong?Thanks.

Post a Reply


Oldest  Newest  Rating
+1 Predrag Kostic · September 12, 2014
I'm not very good at this but doesn't it go like: "you have to load a script that uses an element after the element is created "

I Googled what I put in quotes and this came up: http://www.feedthebot.com/pagespeed/defer-loading-javascript.html

It may be helpful I didn't read through it because I don't have time to try and understand it, sorry.
  • 1

HTML / CSS / Web Design


Discuss, share, ask, learn and teach HTML5 and CSS3.