views:

58

answers:

2

i am new to mootoll what i want is to create a new element span and injuct image to it.

i write following code but not working

      var newElementVar = new Element('span', {'id': 'id_namekhan','text': 'I am a new div'});  

   var my_img = new Element ('img' , {'src' :'uploading/'+json.get('fpath')+'' , 'style' : 'width:50px; text-align:left' }).inject(id_namekhan, 'top') ;

even the text I am a new div is not showing

Thanks

A: 

You're going to need to provide the code you are using for json.get('fpath')

keif
+1  A: 

Your problem is that you are trying to inject the image into the span using its ID, but the span hasn't been added to the page (DOM tree) yet. Try this:

var my_span = new Element('span', {'id': 'id_namekhan','text': 'I am a new div'});
var my_img = new Element ('img' , {'src' :'uploading/'+json.get('fpath')+'' , 'style' : 'width:50px; text-align:left' }).inject(my_span, 'top');
my_span.inject($('element')); // replace element with the ID of the element you wish to inject the span inside
Nathan Kleyn