0

I am looping through drop down option and checking attribute. if attribute match than counter is increase. At the end i show counter as alert. This is my code but some how its not working dont know why

        var count= 0;
        $('.mydropdown option').each(function () {
            var level = this.attr("myattr");
            if (level == "0") {
                count++;
            }
        });
            alert(count);
        }
Saurabh Sharma
  • 139
  • 2
  • 12

1 Answers1

1

this is a plain javascript object, it does not contain a function called .attr()

Try,

 var level = $(this).attr("myattr");

Just convert the this reference into a jquery object and invoke .attr() over it

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130