Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Injecting after multiple elements

    Hi,

    I have a number of input fields on my page, and after them I'd like to Inject an image. However, as I put an ID on the input fields using mootools, the inject function only works after the first instance. Does anyone know if I can add a class to the input fields instead and what the mootools code is to inject after each input field with that class?

    Here is my current code:

    Code:
    $$('div.contentpaneopen_edit input').setProperty('id', 'editbutton');
    
    
    var my_img = new Element ( 'img' , { 'src' : 'http://www.fight4ourchildren.com/images/M_images/edit.png' , 'style' : 'width:18px; height:18px; border:0;' }).injectBefore($('editbutton'));
    Thanks

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,609
    Thanks
    6
    Thanked 997 Times in 970 Posts
    You’ll have to store all relevant input fields in an array, I guess, since you can’t assign an ID more than once on a page. Also, if you would use the same class it wouldn’t help either since all elements are addressed at the same time then. You’d need something like editbutton1, editbutton2, editbutton3, etc.

    I don’t know how for loops in mootools are working but something like
    Code:
    var my_img = new Element ( 'img' , { 'src' : 'http://www.fight4ourchildren.com/images/M_images/edit.png' , 'style' : 'width:18px; height:18px; border:0;' });
    for(i=0;i<$$('div.contentpaneopen_edit input').length;i++) {
    	$$('div.contentpaneopen_edit input').setProperty('id', 'editbutton'+i);
    	my_img.injectBefore($('editbutton'+i));
    }
    Note: that’s just made up from mind without testing. I have not much experience with mootools. It should give you an idea, though.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •