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);
        }
3

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

even after changing its not working
@SaurabhSharma Show your code in jsfiddle.net I'll check..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.