charmingduck
asked on
jquery each
http://api.jquery.com/each/
please take a look at example2, what's the difference between these two methods?
please take a look at example2, what's the difference between these two methods?
<script>
$("span").click(function () {
$("li").each(function(){
$(this).toggleClass("example");
});
});
$("span").click(function () {
$('li').toggleClass("example");
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is no difference as far as functionality is concerned. Both will toggle class 'Example' of li, in case any span is clicked
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
$("span").click(function () {
$('li').toggleClass("examp
});
I actually meant
$("span").click(function () {
$('span li').toggleClass("example"
});
and when you say something else with each of these "li" individually, do you mean like this? am I understanding this correctly? is this the major advantage or difference? or maybe can you show me an example that in some cases it'd be better to choose each over simply using the all ** ?
$("span").click(function () {
$("li").each(function(){
$(this).toggleClass("examp
$(this).somethingelse();
});
});