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


What is file-img ??? it looks like a variable, but it is actually trying to subtract img from the file ... it looks like there is an error. Variables cannot have a dash in their name in javascript



0


source







All Articles