mootools get data of child element of li?

Posted by sea_1987 on Stack Overflow See other posts from Stack Overflow or by sea_1987
Published on 2010-06-01T09:39:51Z Indexed on 2010/06/01 9:43 UTC
Read the original article Hit count: 246

Hi there,

I am trying to get some information of a child element of an li using mootools, essentially my html looks like this,

<li><a href="/home" id="home" class="nav-link">Home</a></li>

I am wanting to be able get the id, class and href of the a tag using mootools, so far my javascript looks similar to this,

$$('.rate').each(function(element,i){
element.addEvent('click', function(){
    var myStyles = ['nostar', 'onestar', 'twostar', 'threestar', 'fourstar', 'fivestar', 'sixstar', 'sevenstar', 'eightstar', 'ninestar', 'tenstar'];
    myStyles.each(function(myStyle){
        if(element.getParent().hasClass(myStyle)){
            element.getParent().removeClass(myStyle)
        }
    });     
    myStyles.each(function(myStyle, index){
        if(index == element.id){
            element.getParent().toggleClass(myStyle);

            var req = new Request({
                method:'post',
                url: '/recipes/save',
                data: {'rating' : element.id},
                onRequest: function(){ alert('Request made. Please wait...');},
                onComplete:function(response){ alert('Response:' + response);}
            }).send();
            alert('Clicked '+element.id);
            alert(element.getChildren().get('href');
        }
    });     

});

});

The final alert in the script is my attempt to the child of the li(element) and its href.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom