I want to execute some function on all class elements. How can i do that?
what i want is something like:
// i want to fire my function on all class elements
$('.myClass').go(function(){
// my function using "this" object
});
i know this is a dumb question, i used to work on propotype for some time and now i don't remember proper function for jquery
Simple:
$(".myClass").each(function() {
...
});
http://api.jquery.com/each/
Just use the common .each()
iterator:
$('.myClass').each(function() {
go($(this));
});
Another option if you're into more elegant code, write your own plugin - good answer can be found in this question: How to create a jQuery plugin with methods?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With