ARRAY OF HTML INPUT TYPE=“BUTTON” IN JQUERY?

David Miller

Total Post:30

Points:210
Posted by  David Miller
 1154  View(s)
Ratings:
Rate this:

I have 3 Html input button in my web page.

<input id="Meal0" runat="server" type="button" class="btn-free arrayinput" />

<input id="Meal1" runat="server" type="button" class="btn-busy arrayinput" />

<input id="Meal2" runat="server" type="button" class="btn-primary arrayinput" />

now I want to have an array of 3 elements in my jquery function:

here is my all code:

 

        $("#btnNextWeek").click(function (e) {

            var MealsButton = $('.arrayinput');

            var Meals = s.split('!~!');

            for (var i = 0; i <= 2; i++) {

 

                MealsButton[i].css("color", "black");

                MealsButton[i].css("width", "200px");

                MealsButton[i].css("height", "60px");

 

                if (Attr[1] == "1") {

                    MealsButton[i].css("class", "btn-app btn-success btn arrayinput");

                    MealsButton[i].css("Buy", Attr[4] + ":" + Attr[3]);

                    MealsButton[i].val("خرید ژتون");

                }

 

                else if (Attr[2] == "1" && Attr[5] != "empty chip") {

                    MealsButton[i].css("class", "btn-app btn-free btn arrayinput");

                    MealsButton[i].css("DelBtn", Attr[5]);

                    if (Attr[6] != "empty chip") {

                        if (Attr[6] != "empty chip") {

                            MealsButton[i].val(Attr[6]);

 

                        }

 

                        else {

                            MealsButton[i].css("class", "btn-app btn-disable btn arrayinput");

 

                            if (Attr[6] != "empty chip") {

                                MealsButton[i].val(Attr[6]);

                            }

                            else {

                                MealsButton[i].val("");

                            }

                        }

                    }

 

                }

 

            }

        });

this error ocured :

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method

how can i have an array of my html input elements and how can access to my array elements ?

  1. sandy taylor

    Post:46

    Points:324
    Re: Array of html input type=“button” in jquery?

    Let me make a suggestion.

    Give a custom class to the inputs

               <input id="Meal0" runat="server" class="arrayinput" type="button" />
                <input id="Meal1" runat="server" class="arrayinput" type="button" />
                <input id="Meal2" runat="server" class="arrayinput" type="button" />

    And Script can go like

      $("#btnNextWeek").click(function (e) {
    
    var MealsButton = $('.arrayinput');
    
    } });

    Meals button will be the array of inputs as you want it.

    You can use MealsButton variable to add any properties since it is equivalent to the selector.

    For example

    MealsButton.css('width','200px');

    If you want to access each element separately. Then

    MealsButton.each(function (index, value) {
    
               $(this).css('width','200px');
    
    });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!