By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

JavaScript createElement, Jquery on click

P: 1
Hey,
I have function where it creates img element and sets id = title,
When i add to index.html jquery
Expand|Select|Wrap|Line Numbers
  1. $('#title').click(function() {
  2.   alert('xx');
  3. });     
it doesn't work, why?


Jscript function:

Expand|Select|Wrap|Line Numbers
  1.  function showUploadedItem (source) {
  2.           var list = document.getElementById("image-list"),
  3.               li   = document.createElement("li"),
  4.             ip   = document.createElement("input"),
  5.               img  = document.createElement("img");
  6.             bild = document.createElement("img");
  7.             bild.src="pencil.png";
  8.             bild.style.width="16px";
  9.             bild.style.height="16px";
  10.             bild.style.cursor="pointer";    
  11.             bild.style.border="0";
  12.             bild.id="title";
  13.           img.src = source;
  14.           li.appendChild(img);
  15.         list.appendChild(li);
  16.         li.appendChild(ip);
  17.         li.appendChild(bild);
  18.  
  19.     } 

Thank you!
Apr 28 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
Id guess that when you call the first code the second is not yet executed. therefore there is no element with the ID "title" to assign an event to (yet).
Apr 28 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.