Mike
Mike

Reputation: 51

Looping through in jQuery

i have written following function in JS which is called on click of some element in Client Side.I want to loop thru in jQuery,but following code is not working.

function HideShowMenu( pStart, pLength)

$(document).ready(function(){

    for ( i=pStart ; i <= pLength ; i++ ) {

        $('#tr_menu_'+i).show();
     } 

});

// return   
return;  
}   

How can i go about it?

Upvotes: 0

Views: 84

Answers (4)

DrStrangeLove
DrStrangeLove

Reputation: 11557

function HideShowMenu() {
    $(document).ready(function(){
        $('#tr_menu_').each(function() {
            $(this).show();
        });
    });
}   

Upvotes: 0

Itai Sagi
Itai Sagi

Reputation: 5615

$('#element').each(function(){
    $(this).show();
});

Upvotes: 0

Andreas Louv
Andreas Louv

Reputation: 47099

$(document).ready(function(){
    HideShowMenu(0, 5);
});
function HideShowMenu(pStart, pLength) {
    for ( var i=pStart; i <= pLength; i++ ) {
        $('#tr_menu_' + i).show();
    } 
}   

Upvotes: 1

J0HN
J0HN

Reputation: 26921

You are misusing $(document).ready();. Correct way is something like this:

function HideShowMenu( pStart, pLength){
    for (var i=pStart ; i <= pLength ; i++ ) {
        $('#tr_menu_'+i).show();
    } 
}   

$(document).ready(function(){
    HideShowMenu(1,10);
});

$(document).ready() should be outside any other function.

Upvotes: 0

Related Questions