Mootools injection function
I have a range that I add up like this:
new Element('span', {'class': 'file-img', 'html': 'Image'})
I want to add an image to it:
var my_img = new Element ('img' , {'src' :'uploading/abc.jpg' ,
'style' : 'width:50px; text-align:left' }).inject(file-img, 'top') ;
Does not work.
Thank you for your help.
+2
source to share
2 answers
this will work (mt 1.2+):
new Element('span', {
'class': 'file-img'
}).inject($(document.body)).adopt(new Element("img", {
'src' :'uploading/abc.jpg',
styles: {
width: 50,
textAlign: "left"
}
});
but if you are trying to use file-img as a reference to the CSS class of the span you created, you need to use document.getElement ("span.file-img") as the target container. and - don't use - in class names if you can help. use _ instead - implies subtraction and can affect the CSS selector.
Another way to do it is to assign it to a variable
eg,
var file_img = new Element("span" ... );
...
someObj.inject(file_img);
+3
source to share