user2130733
user2130733

Reputation: 60

Mootools Injecting new element

I am trying to inject one element in the div which have parent class . There is no problem when i am injecting with the ID selector but once i try using class selector it doesn't work..

window.addEvent('domready',function(){
    var FirstElement = new Element('div', {id: 'FirstElement',text:'test'});
    $('submit').addEvent('click',function(){                
        FirstElement.inject('parent');//working using ID selector               
        FirstElement.inject('div.parent');//not working using Class selector
    });
});

Here is html code

<div class="parent" id="parent"></div>
<input id='submit' value="submit" />

Upvotes: 1

Views: 2429

Answers (1)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

replace with:

FirstElement.inject(document.getElement('div.parent'));

keep in mind this will return the first matching div.parent so if you have more than one, you need to anchor into the form like this.getElement('div.parent') where this is the form element

Upvotes: 2

Related Questions